Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Sean Carolan 2014-03-12 09:53:30 -05:00
commit 8930311acf
32 changed files with 924 additions and 697 deletions

View file

@ -14,11 +14,11 @@ You can install this via the command line with either `curl` or `wget`.
h4. via `curl` h4. via `curl`
@curl -L https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh | sh@ @curl -L http://install.ohmyz.sh | sh@
h4. via `wget` h4. via `wget`
@wget --no-check-certificate https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh@ @wget --no-check-certificate http://install.ohmyz.sh -O - | sh@
h3. The manual way h3. The manual way

View file

@ -6,6 +6,11 @@ alias po='popd'
alias ...='cd ../..' alias ...='cd ../..'
alias -- -='cd -' alias -- -='cd -'
# Prevent headaches
alias cp='cp -v'
alias rm='rm -v'
alias mv='mv -v'
# Super user # Super user
alias _='sudo' alias _='sudo'
alias please='sudo' alias please='sudo'
@ -27,9 +32,9 @@ else
fi fi
# List direcory contents # List direcory contents
alias lsa='ls -lah' alias lsa='ls -lah'
alias l='ls -la' alias l='ls -lah'
alias ll='ls -l' alias ll='ls -lh'
alias la='ls -lA' alias la='ls -lAh'
alias sl=ls # often screw this up alias sl=ls # often screw this up
alias afind='ack-grep -il' alias afind='ack-grep -il'

View file

@ -0,0 +1,33 @@
# *_prompt_info functions for usage in your prompt
#
# Plugin creators, please add your *_prompt_info function to the list
# of dummy implementations to help theme creators not receiving errors
# without the need of implementing conditional clauses.
#
# See also lib/bzr.zsh, lib/git.zsh and lib/nvm.zsh for
# git_prompt_info, bzr_prompt_info and nvm_prompt_info
# Dummy implementations that return false to prevent command_not_found
# errors with themes, that implement these functions
# Real implementations will be used when the respective plugins are loaded
function chruby_prompt_info hg_prompt_info pyenv_prompt_info \
rbenv_prompt_info svn_prompt_info vi_mode_prompt_info \
virtualenv_prompt_info {
return 1
}
# oh-my-zsh supports an rvm prompt by default
# get the name of the rvm ruby version
function rvm_prompt_info() {
[ -f $HOME/.rvm/bin/rvm-prompt ] || return 1
local rvm_prompt
rvm_prompt=$($HOME/.rvm/bin/rvm-prompt ${=ZSH_THEME_RVM_PROMPT_OPTIONS} 2>/dev/null)
[[ "${rvm_prompt}x" == "x" ]] && return 1
echo "${ZSH_THEME_RVM_PROMPT_PREFIX:=(}${rvm_prompt}${ZSH_THEME_RVM_PROMPT_SUFFIX:=)}"
}
# use this to enable users to see their ruby version, no matter which
# version management system they use
function ruby_prompt_info() {
echo $(rvm_prompt_info || rbenv_prompt_info || chruby_prompt_info)
}

View file

@ -1,2 +0,0 @@
# using the rbenv plugin will override this with a real implementation
function rbenv_prompt_info() {}

View file

@ -1,8 +0,0 @@
# get the name of the ruby version
function rvm_prompt_info() {
[ -f $HOME/.rvm/bin/rvm-prompt ] || return
local rvm_prompt
rvm_prompt=$($HOME/.rvm/bin/rvm-prompt ${ZSH_THEME_RVM_PROMPT_OPTIONS} 2>/dev/null)
[[ "${rvm_prompt}x" == "x" ]] && return
echo "${ZSH_THEME_RVM_PROMPT_PREFIX:=(}${rvm_prompt}${ZSH_THEME_RVM_PROMPT_SUFFIX:=)}"
}

View file

@ -27,9 +27,8 @@ function omz_termsupport_preexec {
emulate -L zsh emulate -L zsh
setopt extended_glob setopt extended_glob
local CMD=${1[(wr)^(*=*|sudo|ssh|rake|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd local CMD=${1[(wr)^(*=*|sudo|ssh|rake|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
local LINE="${2:gs/$/\\$}" local LINE="${2:gs/%/%%}"
LINE="${LINE:gs/%/%%}" title '$CMD' '%100>...>$LINE%<<'
title "$CMD" "%100>...>$LINE%<<"
} }
autoload -U add-zsh-hook autoload -U add-zsh-hook

View file

@ -0,0 +1,17 @@
################################################################################
# catimg script by Eduardo San Martin Morote aka Posva #
# http://posva.net #
# #
# Ouput the content of an image to the stdout using the 256 colors of the #
# terminal. #
# Github: https://github.com/posva/catimg #
################################################################################
function catimg() {
if [[ -x `which convert` ]]; then
zsh $ZSH/plugins/catimg/catimg.sh $@
else
echo "catimg need convert (ImageMagick) to work)"
fi
}

88
plugins/catimg/catimg.sh Executable file
View file

@ -0,0 +1,88 @@
################################################################################
# catimg script by Eduardo San Martin Morote aka Posva #
# http://posva.net #
# #
# Ouput the content of an image to the stdout using the 256 colors of the #
# terminal. #
# Github: https://github.com/posva/catimg #
################################################################################
function help() {
echo "Usage catimg [-h] [-w width] [-c char] img"
echo "By default char is \" \" and w is the terminal width"
}
# VARIABLES
COLOR_FILE=$(dirname $0)/colors.png
CHAR=" "
WIDTH=""
IMG=""
while getopts qw:c:h opt; do
case "$opt" in
w) WIDTH="$OPTARG" ;;
c) CHAR="$OPTARG" ;;
h) help; exit ;;
*) help ; exit 1;;
esac
done
while [ "$1" ]; do
IMG="$1"
shift
done
if [ "$IMG" = "" -o ! -f "$IMG" ]; then
help
exit 1
fi
if [ ! "$WIDTH" ]; then
COLS=$(expr $(tput cols) "/" $(echo -n "$CHAR" | wc -c))
else
COLS=$(expr $WIDTH "/" $(echo -n "$CHAR" | wc -c))
fi
WIDTH=$(convert "$IMG" -print "%w\n" /dev/null)
if [ "$WIDTH" -gt "$COLS" ]; then
WIDTH=$COLS
fi
REMAP=""
if convert "$IMG" -resize $COLS\> +dither -remap $COLOR_FILE /dev/null ; then
REMAP="-remap $COLOR_FILE"
else
echo "The version of convert is too old, don't expect good results :(" >&2
#convert "$IMG" -colors 256 PNG8:tmp.png
#IMG="tmp.png"
fi
# Display the image
I=0
convert "$IMG" -resize $COLS\> +dither `echo $REMAP` txt:- 2>/dev/null |
sed -e 's/.*none.*/NO NO NO/g' -e '1d;s/^.*(\(.*\)[,)].*$/\1/g;y/,/ /' |
while read R G B f; do
if [ ! "$R" = "NO" ]; then
if [ "$R" -eq "$G" -a "$G" -eq "$B" ]; then
((
I++,
IDX = 232 + R * 23 / 255
))
else
((
I++,
IDX = 16
+ R * 5 / 255 * 36
+ G * 5 / 255 * 6
+ B * 5 / 255
))
fi
#echo "$R,$G,$B: $IDX"
echo -ne "\e[48;5;${IDX}m${CHAR}"
else
(( I++ ))
echo -ne "\e[0m${CHAR}"
fi
# New lines
(( $I % $WIDTH )) || echo -e "\e[0m"
done

BIN
plugins/catimg/colors.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

View file

@ -0,0 +1,7 @@
alias gemb="gem build *.gemspec"
alias gemp="gem push *.gem"
# gemy GEM 0.0.0 = gem yank GEM -v 0.0.0
function gemy {
gem yank $1 -v $2
}

View file

@ -1,20 +1,30 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: UTF-8 -*- # -*- coding: UTF-8 -*-
from subprocess import Popen, PIPE
import re
# change those symbols to whatever you prefer # change those symbols to whatever you prefer
symbols = {'ahead of': '', 'behind': '', 'staged':'', 'changed':'', 'untracked':'', 'clean':'', 'unmerged':'', 'sha1':':'} symbols = {
'ahead of': '',
'behind': '',
'staged': '',
'changed': '',
'untracked': '',
'clean': '',
'unmerged': '',
'sha1': ':'
}
from subprocess import Popen, PIPE output, error = Popen(
['git', 'status'], stdout=PIPE, stderr=PIPE).communicate()
output,error = Popen(['git','status'], stdout=PIPE, stderr=PIPE).communicate()
if error: if error:
import sys import sys
sys.exit(0) sys.exit(0)
lines = output.splitlines() lines = output.splitlines()
import re behead_re = re.compile(
behead_re = re.compile(r"^# Your branch is (ahead of|behind) '(.*)' by (\d+) commit") r"^# Your branch is (ahead of|behind) '(.*)' by (\d+) commit")
diverge_re = re.compile(r"^# and have (\d+) and (\d+) different") diverge_re = re.compile(r"^# and have (\d+) and (\d+) different")
status = '' status = ''
@ -23,46 +33,50 @@ changed = re.compile(r'^# Changed but not updated:$', re.MULTILINE)
untracked = re.compile(r'^# Untracked files:$', re.MULTILINE) untracked = re.compile(r'^# Untracked files:$', re.MULTILINE)
unmerged = re.compile(r'^# Unmerged paths:$', re.MULTILINE) unmerged = re.compile(r'^# Unmerged paths:$', re.MULTILINE)
def execute(*command): def execute(*command):
out, err = Popen(stdout=PIPE, stderr=PIPE, *command).communicate() out, err = Popen(stdout=PIPE, stderr=PIPE, *command).communicate()
if not err: if not err:
nb = len(out.splitlines()) nb = len(out.splitlines())
else: else:
nb = '?' nb = '?'
return nb return nb
if staged.search(output): if staged.search(output):
nb = execute(['git','diff','--staged','--name-only','--diff-filter=ACDMRT']) nb = execute(
status += '%s%s' % (symbols['staged'], nb) ['git', 'diff', '--staged', '--name-only', '--diff-filter=ACDMRT'])
status += '%s%s' % (symbols['staged'], nb)
if unmerged.search(output): if unmerged.search(output):
nb = execute(['git','diff', '--staged','--name-only', '--diff-filter=U']) nb = execute(['git', 'diff', '--staged', '--name-only', '--diff-filter=U'])
status += '%s%s' % (symbols['unmerged'], nb) status += '%s%s' % (symbols['unmerged'], nb)
if changed.search(output): if changed.search(output):
nb = execute(['git','diff','--name-only', '--diff-filter=ACDMRT']) nb = execute(['git', 'diff', '--name-only', '--diff-filter=ACDMRT'])
status += '%s%s' % (symbols['changed'], nb) status += '%s%s' % (symbols['changed'], nb)
if untracked.search(output): if untracked.search(output):
## nb = len(Popen(['git','ls-files','--others','--exclude-standard'],stdout=PIPE).communicate()[0].splitlines()) status += symbols['untracked']
## status += "%s" % (symbols['untracked']*(nb//3 + 1), )
status += symbols['untracked']
if status == '': if status == '':
status = symbols['clean'] status = symbols['clean']
remote = '' remote = ''
bline = lines[0] bline = lines[0]
if bline.find('Not currently on any branch') != -1: if bline.find('Not currently on any branch') != -1:
branch = symbols['sha1']+ Popen(['git','rev-parse','--short','HEAD'], stdout=PIPE).communicate()[0][:-1] branch = symbols['sha1'] + Popen([
'git',
'rev-parse',
'--short',
'HEAD'], stdout=PIPE).communicate()[0][:-1]
else: else:
branch = bline.split(' ')[3] branch = bline.split(' ')[-1]
bstatusline = lines[1] bstatusline = lines[1]
match = behead_re.match(bstatusline) match = behead_re.match(bstatusline)
if match: if match:
remote = symbols[match.groups()[0]] remote = symbols[match.groups()[0]]
remote += match.groups()[2] remote += match.groups()[2]
elif lines[2:]: elif lines[2:]:
div_match = diverge_re.match(lines[2]) div_match = diverge_re.match(lines[2])
if div_match: if div_match:
remote = "{behind}{1}{ahead of}{0}".format(*div_match.groups(), **symbols) remote = "{behind}{1}{ahead of}{0}".format(
*div_match.groups(), **symbols)
print '\n'.join([branch,remote,status])
print('\n'.join([branch, remote, status]))

View file

@ -62,8 +62,10 @@ alias glgg='git log --graph --max-count=10'
compdef _git glgg=git-log compdef _git glgg=git-log
alias glgga='git log --graph --decorate --all' alias glgga='git log --graph --decorate --all'
compdef _git glgga=git-log compdef _git glgga=git-log
alias glo='git log --oneline' alias glo='git log --oneline --decorate --color'
compdef _git glo=git-log compdef _git glo=git-log
alias glog='git log --oneline --decorate --color --graph'
compdef _git glog=git-log
alias gss='git status -s' alias gss='git status -s'
compdef _git gss=git-status compdef _git gss=git-status
alias ga='git add' alias ga='git add'

View file

@ -2,18 +2,19 @@
# zsh completion wrapper for git # zsh completion wrapper for git
# #
# You need git's bash completion script installed somewhere, by default on the # Copyright (c) 2012-2013 Felipe Contreras <felipe.contreras@gmail.com>
# same directory as this script.
# #
# If your script is on ~/.git-completion.sh instead, you can configure it on # You need git's bash completion script installed somewhere, by default it
# your ~/.zshrc: # would be the location bash-completion uses.
#
# If your script is somewhere else, you can configure it on your ~/.zshrc:
# #
# zstyle ':completion:*:*:git:*' script ~/.git-completion.sh # zstyle ':completion:*:*:git:*' script ~/.git-completion.sh
# #
# The recommended way to install this script is to copy to # The recommended way to install this script is to copy to '~/.zsh/_git', and
# '~/.zsh/completion/_git', and then add the following to your ~/.zshrc file: # then add the following to your ~/.zshrc file:
# #
# fpath=(~/.zsh/completion $fpath) # fpath=(~/.zsh $fpath)
complete () complete ()
{ {
@ -21,8 +22,23 @@ complete ()
return 0 return 0
} }
zstyle -T ':completion:*:*:git:*' tag-order && \
zstyle ':completion:*:*:git:*' tag-order 'common-commands'
zstyle -s ":completion:*:*:git:*" script script zstyle -s ":completion:*:*:git:*" script script
test -z "$script" && script="$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash if [ -z "$script" ]; then
local -a locations
local e
locations=(
'/etc/bash_completion.d/git' # fedora, old debian
'/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
'/usr/share/bash-completion/git' # gentoo
$(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
)
for e in $locations; do
test -f $e && script="$e" && break
done
fi
ZSH_VERSION='' . "$script" ZSH_VERSION='' . "$script"
__gitcomp () __gitcomp ()
@ -69,18 +85,131 @@ __gitcomp_file ()
compadd -Q -p "${2-}" -f -- ${=1} && _ret=0 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
} }
__git_zsh_bash_func ()
{
emulate -L ksh
local command=$1
local completion_func="_git_${command//-/_}"
declare -f $completion_func >/dev/null && $completion_func && return
local expansion=$(__git_aliased_command "$command")
if [ -n "$expansion" ]; then
completion_func="_git_${expansion//-/_}"
declare -f $completion_func >/dev/null && $completion_func
fi
}
__git_zsh_cmd_common ()
{
local -a list
list=(
add:'add file contents to the index'
bisect:'find by binary search the change that introduced a bug'
branch:'list, create, or delete branches'
checkout:'checkout a branch or paths to the working tree'
clone:'clone a repository into a new directory'
commit:'record changes to the repository'
diff:'show changes between commits, commit and working tree, etc'
fetch:'download objects and refs from another repository'
grep:'print lines matching a pattern'
init:'create an empty Git repository or reinitialize an existing one'
log:'show commit logs'
merge:'join two or more development histories together'
mv:'move or rename a file, a directory, or a symlink'
pull:'fetch from and merge with another repository or a local branch'
push:'update remote refs along with associated objects'
rebase:'forward-port local commits to the updated upstream head'
reset:'reset current HEAD to the specified state'
rm:'remove files from the working tree and from the index'
show:'show various types of objects'
status:'show the working tree status'
tag:'create, list, delete or verify a tag object signed with GPG')
_describe -t common-commands 'common commands' list && _ret=0
}
__git_zsh_cmd_alias ()
{
local -a list
list=(${${${(0)"$(git config -z --get-regexp '^alias\.')"}#alias.}%$'\n'*})
_describe -t alias-commands 'aliases' list $* && _ret=0
}
__git_zsh_cmd_all ()
{
local -a list
emulate ksh -c __git_compute_all_commands
list=( ${=__git_all_commands} )
_describe -t all-commands 'all commands' list && _ret=0
}
__git_zsh_main ()
{
local curcontext="$curcontext" state state_descr line
typeset -A opt_args
local -a orig_words
orig_words=( ${words[@]} )
_arguments -C \
'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \
'(-p --paginate)--no-pager[do not pipe git output into a pager]' \
'--git-dir=-[set the path to the repository]: :_directories' \
'--bare[treat the repository as a bare repository]' \
'(- :)--version[prints the git suite version]' \
'--exec-path=-[path to where your core git programs are installed]:: :_directories' \
'--html-path[print the path where git''s HTML documentation is installed]' \
'--info-path[print the path where the Info files are installed]' \
'--man-path[print the manpath (see `man(1)`) for the man pages]' \
'--work-tree=-[set the path to the working tree]: :_directories' \
'--namespace=-[set the git namespace]' \
'--no-replace-objects[do not use replacement refs to replace git objects]' \
'(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \
'(-): :->command' \
'(-)*:: :->arg' && return
case $state in
(command)
_alternative \
'alias-commands:alias:__git_zsh_cmd_alias' \
'common-commands:common:__git_zsh_cmd_common' \
'all-commands:all:__git_zsh_cmd_all' && _ret=0
;;
(arg)
local command="${words[1]}" __git_dir
if (( $+opt_args[--bare] )); then
__git_dir='.'
else
__git_dir=${opt_args[--git-dir]}
fi
(( $+opt_args[--help] )) && command='help'
words=( ${orig_words[@]} )
__git_zsh_bash_func $command
;;
esac
}
_git () _git ()
{ {
local _ret=1 local _ret=1
() { local cur cword prev
emulate -L ksh
local cur cword prev cur=${words[CURRENT]}
cur=${words[CURRENT-1]} prev=${words[CURRENT-1]}
prev=${words[CURRENT-2]} let cword=CURRENT-1
let cword=CURRENT-1
__${service}_main if (( $+functions[__${service}_zsh_main] )); then
} __${service}_zsh_main
let _ret && _default -S '' && _ret=0 else
emulate ksh -c __${service}_main
fi
let _ret && _default && _ret=0
return _ret return _ret
} }

View file

@ -33,8 +33,6 @@ esac
# returns location of .git repo # returns location of .git repo
__gitdir () __gitdir ()
{ {
# Note: this function is duplicated in git-prompt.sh
# When updating it, make sure you update the other one to match.
if [ -z "${1-}" ]; then if [ -z "${1-}" ]; then
if [ -n "${__git_dir-}" ]; then if [ -n "${__git_dir-}" ]; then
echo "$__git_dir" echo "$__git_dir"
@ -53,19 +51,6 @@ __gitdir ()
fi fi
} }
__gitcomp_1 ()
{
local c IFS=$' \t\n'
for c in $1; do
c="$c$2"
case $c in
--*=*|*.) ;;
*) c="$c " ;;
esac
printf '%s\n' "$c"
done
}
# The following function is based on code from: # The following function is based on code from:
# #
# bash_completion - programmable completion functions for bash 3.2+ # bash_completion - programmable completion functions for bash 3.2+
@ -195,8 +180,18 @@ _get_comp_words_by_ref ()
} }
fi fi
# Generates completion reply with compgen, appending a space to possible __gitcompadd ()
# completion words, if necessary. {
local i=0
for x in $1; do
if [[ "$x" == "$3"* ]]; then
COMPREPLY[i++]="$2$x$4"
fi
done
}
# Generates completion reply, appending a space to possible completion words,
# if necessary.
# It accepts 1 to 4 arguments: # It accepts 1 to 4 arguments:
# 1: List of possible completion words. # 1: List of possible completion words.
# 2: A prefix to be added to each possible completion word (optional). # 2: A prefix to be added to each possible completion word (optional).
@ -208,19 +203,25 @@ __gitcomp ()
case "$cur_" in case "$cur_" in
--*=) --*=)
COMPREPLY=()
;; ;;
*) *)
local IFS=$'\n' local c i=0 IFS=$' \t\n'
COMPREPLY=($(compgen -P "${2-}" \ for c in $1; do
-W "$(__gitcomp_1 "${1-}" "${4-}")" \ c="$c${4-}"
-- "$cur_")) if [[ $c == "$cur_"* ]]; then
case $c in
--*=*|*.) ;;
*) c="$c " ;;
esac
COMPREPLY[i++]="${2-}$c"
fi
done
;; ;;
esac esac
} }
# Generates completion reply with compgen from newline-separated possible # Generates completion reply from newline-separated possible completion words
# completion words by appending a space to all of them. # by appending a space to all of them.
# It accepts 1 to 4 arguments: # It accepts 1 to 4 arguments:
# 1: List of possible completion words, separated by a single newline. # 1: List of possible completion words, separated by a single newline.
# 2: A prefix to be added to each possible completion word (optional). # 2: A prefix to be added to each possible completion word (optional).
@ -231,7 +232,7 @@ __gitcomp ()
__gitcomp_nl () __gitcomp_nl ()
{ {
local IFS=$'\n' local IFS=$'\n'
COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}")) __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
} }
# Generates completion reply with compgen from newline-separated possible # Generates completion reply with compgen from newline-separated possible
@ -249,106 +250,50 @@ __gitcomp_file ()
# since tilde expansion is not applied. # since tilde expansion is not applied.
# This means that COMPREPLY will be empty and Bash default # This means that COMPREPLY will be empty and Bash default
# completion will be used. # completion will be used.
COMPREPLY=($(compgen -P "${2-}" -W "$1" -- "${3-$cur}")) __gitcompadd "$1" "${2-}" "${3-$cur}" ""
# Tell Bash that compspec generates filenames. # use a hack to enable file mode in bash < 4
compopt -o filenames 2>/dev/null compopt -o filenames +o nospace 2>/dev/null ||
compgen -f /non-existing-dir/ > /dev/null
} }
__git_index_file_list_filter_compat () # Execute 'git ls-files', unless the --committable option is specified, in
{ # which case it runs 'git diff-index' to find out the files that can be
local path # committed. It return paths relative to the directory specified in the first
# argument, and using the options specified in the second argument.
while read -r path; do
case "$path" in
?*/*) echo "${path%%/*}/" ;;
*) echo "$path" ;;
esac
done
}
__git_index_file_list_filter_bash ()
{
local path
while read -r path; do
case "$path" in
?*/*)
# XXX if we append a slash to directory names when using
# `compopt -o filenames`, Bash will append another slash.
# This is pretty stupid, and this the reason why we have to
# define a compatible version for this function.
echo "${path%%/*}" ;;
*)
echo "$path" ;;
esac
done
}
# Process path list returned by "ls-files" and "diff-index --name-only"
# commands, in order to list only file names relative to a specified
# directory, and append a slash to directory names.
__git_index_file_list_filter ()
{
# Default to Bash >= 4.x
__git_index_file_list_filter_bash
}
# Execute git ls-files, returning paths relative to the directory
# specified in the first argument, and using the options specified in
# the second argument.
__git_ls_files_helper () __git_ls_files_helper ()
{ {
( (
test -n "${CDPATH+set}" && unset CDPATH test -n "${CDPATH+set}" && unset CDPATH
# NOTE: $2 is not quoted in order to support multiple options cd "$1"
cd "$1" && git ls-files --exclude-standard $2 if [ "$2" == "--committable" ]; then
git diff-index --name-only --relative HEAD
else
# NOTE: $2 is not quoted in order to support multiple options
git ls-files --exclude-standard $2
fi
) 2>/dev/null ) 2>/dev/null
} }
# Execute git diff-index, returning paths relative to the directory
# specified in the first argument, and using the tree object id
# specified in the second argument.
__git_diff_index_helper ()
{
(
test -n "${CDPATH+set}" && unset CDPATH
cd "$1" && git diff-index --name-only --relative "$2"
) 2>/dev/null
}
# __git_index_files accepts 1 or 2 arguments: # __git_index_files accepts 1 or 2 arguments:
# 1: Options to pass to ls-files (required). # 1: Options to pass to ls-files (required).
# Supported options are --cached, --modified, --deleted, --others,
# and --directory.
# 2: A directory path (optional). # 2: A directory path (optional).
# If provided, only files within the specified directory are listed. # If provided, only files within the specified directory are listed.
# Sub directories are never recursed. Path must have a trailing # Sub directories are never recursed. Path must have a trailing
# slash. # slash.
__git_index_files () __git_index_files ()
{ {
local dir="$(__gitdir)" root="${2-.}" local dir="$(__gitdir)" root="${2-.}" file
if [ -d "$dir" ]; then if [ -d "$dir" ]; then
__git_ls_files_helper "$root" "$1" | __git_index_file_list_filter | __git_ls_files_helper "$root" "$1" |
sort | uniq while read -r file; do
fi case "$file" in
} ?*/*) echo "${file%%/*}" ;;
*) echo "$file" ;;
# __git_diff_index_files accepts 1 or 2 arguments: esac
# 1) The id of a tree object. done | sort | uniq
# 2) A directory path (optional).
# If provided, only files within the specified directory are listed.
# Sub directories are never recursed. Path must have a trailing
# slash.
__git_diff_index_files ()
{
local dir="$(__gitdir)" root="${2-.}"
if [ -d "$dir" ]; then
__git_diff_index_helper "$root" "$1" | __git_index_file_list_filter |
sort | uniq
fi fi
} }
@ -424,14 +369,8 @@ __git_refs ()
done done
;; ;;
*) *)
git ls-remote "$dir" HEAD ORIG_HEAD 'refs/tags/*' 'refs/heads/*' 'refs/remotes/*' 2>/dev/null | \ echo "HEAD"
while read -r hash i; do git for-each-ref --format="%(refname:short)" -- "refs/remotes/$dir/" | sed -e "s#^$dir/##"
case "$i" in
*^{}) ;;
refs/*) echo "${i#refs/*/}" ;;
*) echo "$i" ;;
esac
done
;; ;;
esac esac
} }
@ -549,44 +488,23 @@ __git_complete_revlist_file ()
} }
# __git_complete_index_file requires 1 argument: the options to pass to # __git_complete_index_file requires 1 argument:
# ls-file # 1: the options to pass to ls-file
#
# The exception is --committable, which finds the files appropriate commit.
__git_complete_index_file () __git_complete_index_file ()
{ {
local pfx cur_="$cur" local pfx="" cur_="$cur"
case "$cur_" in case "$cur_" in
?*/*) ?*/*)
pfx="${cur_%/*}" pfx="${cur_%/*}"
cur_="${cur_##*/}" cur_="${cur_##*/}"
pfx="${pfx}/" pfx="${pfx}/"
__gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
;;
*)
__gitcomp_file "$(__git_index_files "$1")" "" "$cur_"
;; ;;
esac esac
}
# __git_complete_diff_index_file requires 1 argument: the id of a tree __gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
# object
__git_complete_diff_index_file ()
{
local pfx cur_="$cur"
case "$cur_" in
?*/*)
pfx="${cur_%/*}"
cur_="${cur_##*/}"
pfx="${pfx}/"
__gitcomp_file "$(__git_diff_index_files "$1" "$pfx")" "$pfx" "$cur_"
;;
*)
__gitcomp_file "$(__git_diff_index_files "$1")" "" "$cur_"
;;
esac
} }
__git_complete_file () __git_complete_file ()
@ -614,7 +532,6 @@ __git_complete_remote_or_refspec ()
case "$cmd" in case "$cmd" in
push) no_complete_refspec=1 ;; push) no_complete_refspec=1 ;;
fetch) fetch)
COMPREPLY=()
return return
;; ;;
*) ;; *) ;;
@ -630,7 +547,6 @@ __git_complete_remote_or_refspec ()
return return
fi fi
if [ $no_complete_refspec = 1 ]; then if [ $no_complete_refspec = 1 ]; then
COMPREPLY=()
return return
fi fi
[ "$remote" = "." ] && remote= [ "$remote" = "." ] && remote=
@ -732,6 +648,7 @@ __git_list_porcelain_commands ()
cat-file) : plumbing;; cat-file) : plumbing;;
check-attr) : plumbing;; check-attr) : plumbing;;
check-ignore) : plumbing;; check-ignore) : plumbing;;
check-mailmap) : plumbing;;
check-ref-format) : plumbing;; check-ref-format) : plumbing;;
checkout-index) : plumbing;; checkout-index) : plumbing;;
commit-tree) : plumbing;; commit-tree) : plumbing;;
@ -951,7 +868,6 @@ _git_am ()
" "
return return
esac esac
COMPREPLY=()
} }
_git_apply () _git_apply ()
@ -971,7 +887,6 @@ _git_apply ()
" "
return return
esac esac
COMPREPLY=()
} }
_git_add () _git_add ()
@ -1031,7 +946,6 @@ _git_bisect ()
__gitcomp_nl "$(__git_refs)" __gitcomp_nl "$(__git_refs)"
;; ;;
*) *)
COMPREPLY=()
;; ;;
esac esac
} }
@ -1124,9 +1038,14 @@ _git_cherry ()
_git_cherry_pick () _git_cherry_pick ()
{ {
local dir="$(__gitdir)"
if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
__gitcomp "--continue --quit --abort"
return
fi
case "$cur" in case "$cur" in
--*) --*)
__gitcomp "--edit --no-commit" __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
;; ;;
*) *)
__gitcomp_nl "$(__git_refs)" __gitcomp_nl "$(__git_refs)"
@ -1170,7 +1089,6 @@ _git_clone ()
return return
;; ;;
esac esac
COMPREPLY=()
} }
_git_commit () _git_commit ()
@ -1182,13 +1100,6 @@ _git_commit ()
;; ;;
esac esac
case "$prev" in
-c|-C)
__gitcomp_nl "$(__git_refs)" "" "${cur}"
return
;;
esac
case "$cur" in case "$cur" in
--cleanup=*) --cleanup=*)
__gitcomp "default strip verbatim whitespace __gitcomp "default strip verbatim whitespace
@ -1218,7 +1129,7 @@ _git_commit ()
esac esac
if git rev-parse --verify --quiet HEAD >/dev/null; then if git rev-parse --verify --quiet HEAD >/dev/null; then
__git_complete_diff_index_file "HEAD" __git_complete_index_file "--committable"
else else
# This is the first commit # This is the first commit
__git_complete_index_file "--cached" __git_complete_index_file "--cached"
@ -1251,7 +1162,7 @@ __git_diff_common_options="--stat --numstat --shortstat --summary
--no-prefix --src-prefix= --dst-prefix= --no-prefix --src-prefix= --dst-prefix=
--inter-hunk-context= --inter-hunk-context=
--patience --histogram --minimal --patience --histogram --minimal
--raw --raw --word-diff
--dirstat --dirstat= --dirstat-by-file --dirstat --dirstat= --dirstat-by-file
--dirstat-by-file= --cumulative --dirstat-by-file= --cumulative
--diff-algorithm= --diff-algorithm=
@ -1299,7 +1210,7 @@ _git_difftool ()
return return
;; ;;
esac esac
__git_complete_file __git_complete_revlist_file
} }
__git_fetch_options=" __git_fetch_options="
@ -1319,11 +1230,12 @@ _git_fetch ()
} }
__git_format_patch_options=" __git_format_patch_options="
--stdout --attach --no-attach --thread --thread= --output-directory --stdout --attach --no-attach --thread --thread= --no-thread
--numbered --start-number --numbered-files --keep-subject --signoff --numbered --start-number --numbered-files --keep-subject --signoff
--signature --no-signature --in-reply-to= --cc= --full-index --binary --signature --no-signature --in-reply-to= --cc= --full-index --binary
--not --all --cover-letter --no-prefix --src-prefix= --dst-prefix= --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
--inline --suffix= --ignore-if-in-upstream --subject-prefix= --inline --suffix= --ignore-if-in-upstream --subject-prefix=
--output-directory --reroll-count --to= --quiet --notes
" "
_git_format_patch () _git_format_patch ()
@ -1354,7 +1266,6 @@ _git_fsck ()
return return
;; ;;
esac esac
COMPREPLY=()
} }
_git_gc () _git_gc ()
@ -1365,7 +1276,6 @@ _git_gc ()
return return
;; ;;
esac esac
COMPREPLY=()
} }
_git_gitk () _git_gitk ()
@ -1442,7 +1352,6 @@ _git_init ()
return return
;; ;;
esac esac
COMPREPLY=()
} }
_git_ls_files () _git_ls_files ()
@ -1578,7 +1487,6 @@ _git_mergetool ()
return return
;; ;;
esac esac
COMPREPLY=()
} }
_git_merge_base () _git_merge_base ()
@ -1819,7 +1727,7 @@ __git_config_get_set_variables ()
_git_config () _git_config ()
{ {
case "$prev" in case "$prev" in
branch.*.remote) branch.*.remote|branch.*.pushremote)
__gitcomp_nl "$(__git_remotes)" __gitcomp_nl "$(__git_remotes)"
return return
;; ;;
@ -1827,11 +1735,19 @@ _git_config ()
__gitcomp_nl "$(__git_refs)" __gitcomp_nl "$(__git_refs)"
return return
;; ;;
branch.*.rebase)
__gitcomp "false true"
return
;;
remote.pushdefault)
__gitcomp_nl "$(__git_remotes)"
return
;;
remote.*.fetch) remote.*.fetch)
local remote="${prev#remote.}" local remote="${prev#remote.}"
remote="${remote%.fetch}" remote="${remote%.fetch}"
if [ -z "$cur" ]; then if [ -z "$cur" ]; then
COMPREPLY=("refs/heads/") __gitcomp_nl "refs/heads/" "" "" ""
return return
fi fi
__gitcomp_nl "$(__git_refs_remotes "$remote")" __gitcomp_nl "$(__git_refs_remotes "$remote")"
@ -1866,6 +1782,10 @@ _git_config ()
" "
return return
;; ;;
diff.submodule)
__gitcomp "log short"
return
;;
help.format) help.format)
__gitcomp "man info web html" __gitcomp "man info web html"
return return
@ -1891,7 +1811,6 @@ _git_config ()
return return
;; ;;
*.*) *.*)
COMPREPLY=()
return return
;; ;;
esac esac
@ -1908,7 +1827,7 @@ _git_config ()
;; ;;
branch.*.*) branch.*.*)
local pfx="${cur%.*}." cur_="${cur##*.}" local pfx="${cur%.*}." cur_="${cur##*.}"
__gitcomp "remote merge mergeoptions rebase" "$pfx" "$cur_" __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
return return
;; ;;
branch.*) branch.*)
@ -2039,7 +1958,6 @@ _git_config ()
core.fileMode core.fileMode
core.fsyncobjectfiles core.fsyncobjectfiles
core.gitProxy core.gitProxy
core.ignoreCygwinFSTricks
core.ignoreStat core.ignoreStat
core.ignorecase core.ignorecase
core.logAllRefUpdates core.logAllRefUpdates
@ -2061,13 +1979,14 @@ _git_config ()
core.whitespace core.whitespace
core.worktree core.worktree
diff.autorefreshindex diff.autorefreshindex
diff.statGraphWidth
diff.external diff.external
diff.ignoreSubmodules diff.ignoreSubmodules
diff.mnemonicprefix diff.mnemonicprefix
diff.noprefix diff.noprefix
diff.renameLimit diff.renameLimit
diff.renames diff.renames
diff.statGraphWidth
diff.submodule
diff.suppressBlankEmpty diff.suppressBlankEmpty
diff.tool diff.tool
diff.wordRegex diff.wordRegex
@ -2202,6 +2121,7 @@ _git_config ()
receive.fsckObjects receive.fsckObjects
receive.unpackLimit receive.unpackLimit
receive.updateserverinfo receive.updateserverinfo
remote.pushdefault
remotes. remotes.
repack.usedeltabaseoffset repack.usedeltabaseoffset
rerere.autoupdate rerere.autoupdate
@ -2272,7 +2192,6 @@ _git_remote ()
__gitcomp "$c" __gitcomp "$c"
;; ;;
*) *)
COMPREPLY=()
;; ;;
esac esac
} }
@ -2356,7 +2275,7 @@ _git_show ()
return return
;; ;;
esac esac
__git_complete_file __git_complete_revlist_file
} }
_git_show_branch () _git_show_branch ()
@ -2388,8 +2307,6 @@ _git_stash ()
*) *)
if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
__gitcomp "$subcommands" __gitcomp "$subcommands"
else
COMPREPLY=()
fi fi
;; ;;
esac esac
@ -2402,14 +2319,12 @@ _git_stash ()
__gitcomp "--index --quiet" __gitcomp "--index --quiet"
;; ;;
show,--*|drop,--*|branch,--*) show,--*|drop,--*|branch,--*)
COMPREPLY=()
;; ;;
show,*|apply,*|drop,*|pop,*|branch,*) show,*|apply,*|drop,*|pop,*|branch,*)
__gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \ __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
| sed -n -e 's/:.*//p')" | sed -n -e 's/:.*//p')"
;; ;;
*) *)
COMPREPLY=()
;; ;;
esac esac
fi fi
@ -2419,7 +2334,7 @@ _git_submodule ()
{ {
__git_has_doubledash && return __git_has_doubledash && return
local subcommands="add status init update summary foreach sync" local subcommands="add status init deinit update summary foreach sync"
if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
case "$cur" in case "$cur" in
--*) --*)
@ -2451,7 +2366,7 @@ _git_svn ()
--no-metadata --use-svm-props --use-svnsync-props --no-metadata --use-svm-props --use-svnsync-props
--log-window-size= --no-checkout --quiet --log-window-size= --no-checkout --quiet
--repack-flags --use-log-author --localtime --repack-flags --use-log-author --localtime
--ignore-paths= $remote_opts --ignore-paths= --include-paths= $remote_opts
" "
local init_opts=" local init_opts="
--template= --shared= --trunk= --tags= --template= --shared= --trunk= --tags=
@ -2526,7 +2441,6 @@ _git_svn ()
__gitcomp "--revision= --parent" __gitcomp "--revision= --parent"
;; ;;
*) *)
COMPREPLY=()
;; ;;
esac esac
fi fi
@ -2551,13 +2465,10 @@ _git_tag ()
case "$prev" in case "$prev" in
-m|-F) -m|-F)
COMPREPLY=()
;; ;;
-*|tag) -*|tag)
if [ $f = 1 ]; then if [ $f = 1 ]; then
__gitcomp_nl "$(__git_tags)" __gitcomp_nl "$(__git_tags)"
else
COMPREPLY=()
fi fi
;; ;;
*) *)
@ -2579,9 +2490,10 @@ __git_main ()
i="${words[c]}" i="${words[c]}"
case "$i" in case "$i" in
--git-dir=*) __git_dir="${i#--git-dir=}" ;; --git-dir=*) __git_dir="${i#--git-dir=}" ;;
--git-dir) ((c++)) ; __git_dir="${words[c]}" ;;
--bare) __git_dir="." ;; --bare) __git_dir="." ;;
--help) command="help"; break ;; --help) command="help"; break ;;
-c) c=$((++c)) ;; -c|--work-tree|--namespace) ((c++)) ;;
-*) ;; -*) ;;
*) command="$i"; break ;; *) command="$i"; break ;;
esac esac
@ -2599,6 +2511,7 @@ __git_main ()
--exec-path --exec-path
--exec-path= --exec-path=
--html-path --html-path
--man-path
--info-path --info-path
--work-tree= --work-tree=
--namespace= --namespace=
@ -2693,35 +2606,19 @@ if [[ -n ${ZSH_VERSION-} ]]; then
compadd -Q -p "${2-}" -f -- ${=1} && _ret=0 compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
} }
__git_zsh_helper ()
{
emulate -L ksh
local cur cword prev
cur=${words[CURRENT-1]}
prev=${words[CURRENT-2]}
let cword=CURRENT-1
__${service}_main
}
_git () _git ()
{ {
emulate -L zsh local _ret=1 cur cword prev
local _ret=1 cur=${words[CURRENT]}
__git_zsh_helper prev=${words[CURRENT-1]}
let _ret && _default -S '' && _ret=0 let cword=CURRENT-1
emulate ksh -c __${service}_main
let _ret && _default && _ret=0
return _ret return _ret
} }
compdef _git git gitk compdef _git git gitk
return return
elif [[ -n ${BASH_VERSION-} ]]; then
if ((${BASH_VERSINFO[0]} < 4)); then
# compopt is not supported
__git_index_file_list_filter ()
{
__git_index_file_list_filter_compat
}
fi
fi fi
__git_func_wrap () __git_func_wrap ()

View file

@ -3,7 +3,7 @@
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org> # Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Distributed under the GNU General Public License, version 2.0. # Distributed under the GNU General Public License, version 2.0.
# #
# This script allows you to see the current branch in your prompt. # This script allows you to see repository status in your prompt.
# #
# To enable: # To enable:
# #
@ -13,23 +13,27 @@
# 3a) Change your PS1 to call __git_ps1 as # 3a) Change your PS1 to call __git_ps1 as
# command-substitution: # command-substitution:
# Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' # Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
# ZSH: PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ ' # ZSH: setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ '
# the optional argument will be used as format string. # the optional argument will be used as format string.
# 3b) Alternatively, if you are using bash, __git_ps1 can be # 3b) Alternatively, for a slightly faster prompt, __git_ps1 can
# used for PROMPT_COMMAND with two parameters, <pre> and # be used for PROMPT_COMMAND in Bash or for precmd() in Zsh
# <post>, which are strings you would put in $PS1 before # with two parameters, <pre> and <post>, which are strings
# and after the status string generated by the git-prompt # you would put in $PS1 before and after the status string
# machinery. e.g. # generated by the git-prompt machinery. e.g.
# PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "' # Bash: PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
# will show username, at-sign, host, colon, cwd, then # will show username, at-sign, host, colon, cwd, then
# various status string, followed by dollar and SP, as # various status string, followed by dollar and SP, as
# your prompt. # your prompt.
# ZSH: precmd () { __git_ps1 "%n" ":%~$ " "|%s" }
# will show username, pipe, then various status string,
# followed by colon, cwd, dollar and SP, as your prompt.
# Optionally, you can supply a third argument with a printf # Optionally, you can supply a third argument with a printf
# format string to finetune the output of the branch status # format string to finetune the output of the branch status
# #
# The argument to __git_ps1 will be displayed only if you are currently # The repository status will be displayed only if you are currently in a
# in a git repository. The %s token will be the name of the current # git repository. The %s token is the placeholder for the shown status.
# branch. #
# The prompt status always includes the current branch name.
# #
# In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value, # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,
# unstaged (*) and staged (+) changes will be shown next to the branch # unstaged (*) and staged (+) changes will be shown next to the branch
@ -77,31 +81,8 @@
# #
# If you would like a colored hint about the current dirty state, set # If you would like a colored hint about the current dirty state, set
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
# the colored output of "git status -sb". # the colored output of "git status -sb" and are available only when
# using __git_ps1 for PROMPT_COMMAND or precmd.
# __gitdir accepts 0 or 1 arguments (i.e., location)
# returns location of .git repo
__gitdir ()
{
# Note: this function is duplicated in git-completion.bash
# When updating it, make sure you update the other one to match.
if [ -z "${1-}" ]; then
if [ -n "${__git_dir-}" ]; then
echo "$__git_dir"
elif [ -n "${GIT_DIR-}" ]; then
test -d "${GIT_DIR-}" || return 1
echo "$GIT_DIR"
elif [ -d .git ]; then
echo .git
else
git rev-parse --git-dir 2>/dev/null
fi
elif [ -d "$1/.git" ]; then
echo "$1/.git"
else
echo "$1"
fi
}
# stores the divergence from upstream in $p # stores the divergence from upstream in $p
# used by GIT_PS1_SHOWUPSTREAM # used by GIT_PS1_SHOWUPSTREAM
@ -124,7 +105,7 @@ __git_ps1_show_upstream ()
fi fi
;; ;;
svn-remote.*.url) svn-remote.*.url)
svn_remote[ $((${#svn_remote[@]} + 1)) ]="$value" svn_remote[$((${#svn_remote[@]} + 1))]="$value"
svn_url_pattern+="\\|$value" svn_url_pattern+="\\|$value"
upstream=svn+git # default upstream is SVN if available, else git upstream=svn+git # default upstream is SVN if available, else git
;; ;;
@ -146,10 +127,11 @@ __git_ps1_show_upstream ()
svn*) svn*)
# get the upstream from the "git-svn-id: ..." in a commit message # get the upstream from the "git-svn-id: ..." in a commit message
# (git-svn uses essentially the same procedure internally) # (git-svn uses essentially the same procedure internally)
local svn_upstream=($(git log --first-parent -1 \ local -a svn_upstream
svn_upstream=($(git log --first-parent -1 \
--grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null)) --grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
if [[ 0 -ne ${#svn_upstream[@]} ]]; then if [[ 0 -ne ${#svn_upstream[@]} ]]; then
svn_upstream=${svn_upstream[ ${#svn_upstream[@]} - 2 ]} svn_upstream=${svn_upstream[${#svn_upstream[@]} - 2]}
svn_upstream=${svn_upstream%@*} svn_upstream=${svn_upstream%@*}
local n_stop="${#svn_remote[@]}" local n_stop="${#svn_remote[@]}"
for ((n=1; n <= n_stop; n++)); do for ((n=1; n <= n_stop; n++)); do
@ -222,6 +204,51 @@ __git_ps1_show_upstream ()
} }
# Helper function that is meant to be called from __git_ps1. It
# injects color codes into the appropriate gitstring variables used
# to build a gitstring.
__git_ps1_colorize_gitstring ()
{
if [[ -n ${ZSH_VERSION-} ]]; then
local c_red='%F{red}'
local c_green='%F{green}'
local c_lblue='%F{blue}'
local c_clear='%f'
else
# Using \[ and \] around colors is necessary to prevent
# issues with command line editing/browsing/completion!
local c_red='\[\e[31m\]'
local c_green='\[\e[32m\]'
local c_lblue='\[\e[1;34m\]'
local c_clear='\[\e[0m\]'
fi
local bad_color=$c_red
local ok_color=$c_green
local flags_color="$c_lblue"
local branch_color=""
if [ $detached = no ]; then
branch_color="$ok_color"
else
branch_color="$bad_color"
fi
c="$branch_color$c"
z="$c_clear$z"
if [ "$w" = "*" ]; then
w="$bad_color$w"
fi
if [ -n "$i" ]; then
i="$ok_color$i"
fi
if [ -n "$s" ]; then
s="$flags_color$s"
fi
if [ -n "$u" ]; then
u="$bad_color$u"
fi
r="$c_clear$r"
}
# __git_ps1 accepts 0 or 1 arguments (i.e., format string) # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
# when called from PS1 using command substitution # when called from PS1 using command substitution
@ -254,39 +281,83 @@ __git_ps1 ()
;; ;;
esac esac
local g="$(__gitdir)" local repo_info rev_parse_exit_code
if [ -z "$g" ]; then repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
--is-bare-repository --is-inside-work-tree \
--short HEAD 2>/dev/null)"
rev_parse_exit_code="$?"
if [ -z "$repo_info" ]; then
if [ $pcmode = yes ]; then if [ $pcmode = yes ]; then
#In PC mode PS1 always needs to be set #In PC mode PS1 always needs to be set
PS1="$ps1pc_start$ps1pc_end" PS1="$ps1pc_start$ps1pc_end"
fi fi
else return
local r="" fi
local b=""
local short_sha
if [ "$rev_parse_exit_code" = "0" ]; then
short_sha="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
fi
local inside_worktree="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
local bare_repo="${repo_info##*$'\n'}"
repo_info="${repo_info%$'\n'*}"
local inside_gitdir="${repo_info##*$'\n'}"
local g="${repo_info%$'\n'*}"
local r=""
local b=""
local step=""
local total=""
if [ -d "$g/rebase-merge" ]; then
read b 2>/dev/null <"$g/rebase-merge/head-name"
read step 2>/dev/null <"$g/rebase-merge/msgnum"
read total 2>/dev/null <"$g/rebase-merge/end"
if [ -f "$g/rebase-merge/interactive" ]; then if [ -f "$g/rebase-merge/interactive" ]; then
r="|REBASE-i" r="|REBASE-i"
b="$(cat "$g/rebase-merge/head-name")"
elif [ -d "$g/rebase-merge" ]; then
r="|REBASE-m"
b="$(cat "$g/rebase-merge/head-name")"
else else
if [ -d "$g/rebase-apply" ]; then r="|REBASE-m"
if [ -f "$g/rebase-apply/rebasing" ]; then fi
r="|REBASE" else
elif [ -f "$g/rebase-apply/applying" ]; then if [ -d "$g/rebase-apply" ]; then
r="|AM" read step 2>/dev/null <"$g/rebase-apply/next"
else read total 2>/dev/null <"$g/rebase-apply/last"
r="|AM/REBASE" if [ -f "$g/rebase-apply/rebasing" ]; then
fi read b 2>/dev/null <"$g/rebase-apply/head-name"
elif [ -f "$g/MERGE_HEAD" ]; then r="|REBASE"
r="|MERGING" elif [ -f "$g/rebase-apply/applying" ]; then
elif [ -f "$g/CHERRY_PICK_HEAD" ]; then r="|AM"
r="|CHERRY-PICKING" else
elif [ -f "$g/BISECT_LOG" ]; then r="|AM/REBASE"
r="|BISECTING"
fi fi
elif [ -f "$g/MERGE_HEAD" ]; then
r="|MERGING"
elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
r="|CHERRY-PICKING"
elif [ -f "$g/REVERT_HEAD" ]; then
r="|REVERTING"
elif [ -f "$g/BISECT_LOG" ]; then
r="|BISECTING"
fi
b="$(git symbolic-ref HEAD 2>/dev/null)" || { if [ -n "$b" ]; then
:
elif [ -h "$g/HEAD" ]; then
# symlink symbolic ref
b="$(git symbolic-ref HEAD 2>/dev/null)"
else
local head=""
if ! read head 2>/dev/null <"$g/HEAD"; then
if [ $pcmode = yes ]; then
PS1="$ps1pc_start$ps1pc_end"
fi
return
fi
# is it a symbolic ref?
b="${head#ref: }"
if [ "$head" = "$b" ]; then
detached=yes detached=yes
b="$( b="$(
case "${GIT_PS1_DESCRIBE_STYLE-}" in case "${GIT_PS1_DESCRIBE_STYLE-}" in
@ -300,100 +371,75 @@ __git_ps1 ()
git describe --tags --exact-match HEAD ;; git describe --tags --exact-match HEAD ;;
esac 2>/dev/null)" || esac 2>/dev/null)" ||
b="$(cut -c1-7 "$g/HEAD" 2>/dev/null)..." || b="$short_sha..."
b="unknown"
b="($b)" b="($b)"
}
fi
local w=""
local i=""
local s=""
local u=""
local c=""
local p=""
if [ "true" = "$(git rev-parse --is-inside-git-dir 2>/dev/null)" ]; then
if [ "true" = "$(git rev-parse --is-bare-repository 2>/dev/null)" ]; then
c="BARE:"
else
b="GIT_DIR!"
fi fi
elif [ "true" = "$(git rev-parse --is-inside-work-tree 2>/dev/null)" ]; then
if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
[ "$(git config --bool bash.showDirtyState)" != "false" ]
then
git diff --no-ext-diff --quiet --exit-code || w="*"
if git rev-parse --quiet --verify HEAD >/dev/null; then
git diff-index --cached --quiet HEAD -- || i="+"
else
i="#"
fi
fi
if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ]; then
git rev-parse --verify refs/stash >/dev/null 2>&1 && s="$"
fi
if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
[ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
[ -n "$(git ls-files --others --exclude-standard)" ]
then
u="%%"
fi
if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
__git_ps1_show_upstream
fi
fi
local f="$w$i$s$u"
if [ $pcmode = yes ]; then
local gitstring=
if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
local c_red='\e[31m'
local c_green='\e[32m'
local c_lblue='\e[1;34m'
local c_clear='\e[0m'
local bad_color=$c_red
local ok_color=$c_green
local branch_color="$c_clear"
local flags_color="$c_lblue"
local branchstring="$c${b##refs/heads/}"
if [ $detached = no ]; then
branch_color="$ok_color"
else
branch_color="$bad_color"
fi
# Setting gitstring directly with \[ and \] around colors
# is necessary to prevent wrapping issues!
gitstring="\[$branch_color\]$branchstring\[$c_clear\]"
if [ -n "$w$i$s$u$r$p" ]; then
gitstring="$gitstring "
fi
if [ "$w" = "*" ]; then
gitstring="$gitstring\[$bad_color\]$w"
fi
if [ -n "$i" ]; then
gitstring="$gitstring\[$ok_color\]$i"
fi
if [ -n "$s" ]; then
gitstring="$gitstring\[$flags_color\]$s"
fi
if [ -n "$u" ]; then
gitstring="$gitstring\[$bad_color\]$u"
fi
gitstring="$gitstring\[$c_clear\]$r$p"
else
gitstring="$c${b##refs/heads/}${f:+ $f}$r$p"
fi
gitstring=$(printf -- "$printf_format" "$gitstring")
PS1="$ps1pc_start$gitstring$ps1pc_end"
else
# NO color option unless in PROMPT_COMMAND mode
printf -- "$printf_format" "$c${b##refs/heads/}${f:+ $f}$r$p"
fi fi
fi fi
if [ -n "$step" ] && [ -n "$total" ]; then
r="$r $step/$total"
fi
local w=""
local i=""
local s=""
local u=""
local c=""
local p=""
if [ "true" = "$inside_gitdir" ]; then
if [ "true" = "$bare_repo" ]; then
c="BARE:"
else
b="GIT_DIR!"
fi
elif [ "true" = "$inside_worktree" ]; then
if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
[ "$(git config --bool bash.showDirtyState)" != "false" ]
then
git diff --no-ext-diff --quiet --exit-code || w="*"
if [ -n "$short_sha" ]; then
git diff-index --cached --quiet HEAD -- || i="+"
else
i="#"
fi
fi
if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] &&
[ -r "$g/refs/stash" ]; then
s="$"
fi
if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
[ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
git ls-files --others --exclude-standard --error-unmatch -- '*' >/dev/null 2>/dev/null
then
u="%${ZSH_VERSION+%}"
fi
if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
__git_ps1_show_upstream
fi
fi
local z="${GIT_PS1_STATESEPARATOR-" "}"
# NO color option unless in PROMPT_COMMAND mode
if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
__git_ps1_colorize_gitstring
fi
local f="$w$i$s$u"
local gitstring="$c${b##refs/heads/}${f:+$z$f}$r$p"
if [ $pcmode = yes ]; then
if [[ -n ${ZSH_VERSION-} ]]; then
gitstring=$(printf -- "$printf_format" "$gitstring")
else
printf -v gitstring -- "$printf_format" "$gitstring"
fi
PS1="$ps1pc_start$gitstring$ps1pc_end"
else
printf -- "$printf_format" "$gitstring"
fi
} }

View file

@ -1,151 +0,0 @@
# install in /etc/zsh/zshrc or your personal .zshrc
# gc
prefixes=(5 6 8)
for p in $prefixes; do
compctl -g "*.${p}" ${p}l
compctl -g "*.go" ${p}g
done
# standard go tools
compctl -g "*.go" gofmt
# gccgo
compctl -g "*.go" gccgo
# go tool
__go_tool_complete() {
typeset -a commands build_flags
commands+=(
'build[compile packages and dependencies]'
'clean[remove object files]'
'doc[run godoc on package sources]'
'fix[run go tool fix on packages]'
'fmt[run gofmt on package sources]'
'get[download and install packages and dependencies]'
'help[display help]'
'install[compile and install packages and dependencies]'
'list[list packages]'
'run[compile and run Go program]'
'test[test packages]'
'tool[run specified go tool]'
'version[print Go version]'
'vet[run go tool vet on packages]'
)
if (( CURRENT == 2 )); then
# explain go commands
_values 'go tool commands' ${commands[@]}
return
fi
build_flags=(
'-a[force reinstallation of packages that are already up-to-date]'
'-n[print the commands but do not run them]'
"-p[number of parallel builds]:number"
'-x[print the commands]'
"-work[print temporary directory name and keep it]"
"-gcflags[flags for 5g/6g/8g]:flags"
"-ldflags[flags for 5l/6l/8l]:flags"
"-gccgoflags[flags for gccgo]:flags"
)
__go_list() {
local expl importpaths
declare -a importpaths
importpaths=($(go list ${words[$CURRENT]}... 2>/dev/null))
_wanted importpaths expl 'import paths' compadd "$@" - "${importpaths[@]}"
}
case ${words[2]} in
clean|doc)
_arguments -s -w : '*:importpaths:__go_list'
;;
fix|fmt|list|vet)
_alternative ':importpaths:__go_list' ':files:_path_files -g "*.go"'
;;
install)
_arguments -s -w : ${build_flags[@]} \
"-v[show package names]" \
'*:importpaths:__go_list'
;;
get)
_arguments -s -w : \
${build_flags[@]}
;;
build)
_arguments -s -w : \
${build_flags[@]} \
"-v[show package names]" \
"-o[output file]:file:_files" \
"*:args:{ _alternative ':importpaths:__go_list' ':files:_path_files -g \"*.go\"' }"
;;
test)
_arguments -s -w : \
${build_flags[@]} \
"-c[do not run, compile the test binary]" \
"-i[do not run, install dependencies]" \
"-v[print test output]" \
"-x[print the commands]" \
"-short[use short mode]" \
"-parallel[number of parallel tests]:number" \
"-cpu[values of GOMAXPROCS to use]:number list" \
"-run[run tests and examples matching regexp]:regexp" \
"-bench[run benchmarks matching regexp]:regexp" \
"-benchtime[run each benchmark during n seconds]:duration" \
"-timeout[kill test after that duration]:duration" \
"-cpuprofile[write CPU profile to file]:file:_files" \
"-memprofile[write heap profile to file]:file:_files" \
"-memprofilerate[set heap profiling rate]:number" \
"*:args:{ _alternative ':importpaths:__go_list' ':files:_path_files -g \"*.go\"' }"
;;
help)
_values "${commands[@]}" \
'gopath[GOPATH environment variable]' \
'importpath[description of import paths]' \
'remote[remote import path syntax]' \
'testflag[description of testing flags]' \
'testfunc[description of testing functions]'
;;
run)
_arguments -s -w : \
${build_flags[@]} \
'*:file:_path_files -g "*.go"'
;;
tool)
if (( CURRENT == 3 )); then
_values "go tool" $(go tool)
return
fi
case ${words[3]} in
[568]g)
_arguments -s -w : \
'-I[search for packages in DIR]:includes:_path_files -/' \
'-L[show full path in file:line prints]' \
'-S[print the assembly language]' \
'-V[print the compiler version]' \
'-e[no limit on number of errors printed]' \
'-h[panic on an error]' \
'-l[disable inlining]' \
'-m[print optimization decisions]' \
'-o[file specify output file]:file' \
'-p[assumed import path for this code]:importpath' \
'-u[disable package unsafe]' \
"*:file:_files -g '*.go'"
;;
[568]l)
local O=${words[3]%l}
_arguments -s -w : \
'-o[file specify output file]:file' \
'-L[search for packages in DIR]:includes:_path_files -/' \
"*:file:_files -g '*.[ao$O]'"
;;
dist)
_values "dist tool" banner bootstrap clean env install version
;;
*)
# use files by default
_files
;;
esac
;;
esac
}
compdef __go_tool_complete go

1
plugins/go/go.plugin.zsh Symbolic link
View file

@ -0,0 +1 @@
../golang/golang.plugin.zsh

View file

@ -1,9 +1,10 @@
# From : http://golang.org/misc/zsh/go?m=text # install in /etc/zsh/zshrc or your personal .zshrc
# gc # gc
prefixes=(5 6 8) prefixes=(5 6 8)
for p in $prefixes; do for p in $prefixes; do
compctl -g "*.${p}" ${p}l compctl -g "*.${p}" ${p}l
compctl -g "*.go" ${p}g compctl -g "*.go" ${p}g
done done
# standard go tools # standard go tools
@ -19,6 +20,7 @@ __go_tool_complete() {
'build[compile packages and dependencies]' 'build[compile packages and dependencies]'
'clean[remove object files]' 'clean[remove object files]'
'doc[run godoc on package sources]' 'doc[run godoc on package sources]'
'env[print Go environment information]'
'fix[run go tool fix on packages]' 'fix[run go tool fix on packages]'
'fmt[run gofmt on package sources]' 'fmt[run gofmt on package sources]'
'get[download and install packages and dependencies]' 'get[download and install packages and dependencies]'
@ -39,12 +41,17 @@ __go_tool_complete() {
build_flags=( build_flags=(
'-a[force reinstallation of packages that are already up-to-date]' '-a[force reinstallation of packages that are already up-to-date]'
'-n[print the commands but do not run them]' '-n[print the commands but do not run them]'
"-p[number of parallel builds]:number" '-p[number of parallel builds]:number'
'-race[enable data race detection]'
'-x[print the commands]' '-x[print the commands]'
"-work[print temporary directory name and keep it]" '-work[print temporary directory name and keep it]'
"-gcflags[flags for 5g/6g/8g]:flags" '-ccflags[flags for 5c/6c/8c]:flags'
"-ldflags[flags for 5l/6l/8l]:flags" '-gcflags[flags for 5g/6g/8g]:flags'
"-gccgoflags[flags for gccgo]:flags" '-ldflags[flags for 5l/6l/8l]:flags'
'-gccgoflags[flags for gccgo]:flags'
'-compiler[name of compiler to use]:name'
'-installsuffix[suffix to add to package directory]:suffix'
'-tags[list of build tags to consider satisfied]:tags'
) )
__go_list() { __go_list() {
local expl importpaths local expl importpaths
@ -62,7 +69,7 @@ __go_tool_complete() {
install) install)
_arguments -s -w : ${build_flags[@]} \ _arguments -s -w : ${build_flags[@]} \
"-v[show package names]" \ "-v[show package names]" \
'*:importpaths:__go_list' '*:importpaths:__go_list'
;; ;;
get) get)
_arguments -s -w : \ _arguments -s -w : \
@ -87,7 +94,10 @@ __go_tool_complete() {
"-cpu[values of GOMAXPROCS to use]:number list" \ "-cpu[values of GOMAXPROCS to use]:number list" \
"-run[run tests and examples matching regexp]:regexp" \ "-run[run tests and examples matching regexp]:regexp" \
"-bench[run benchmarks matching regexp]:regexp" \ "-bench[run benchmarks matching regexp]:regexp" \
"-benchtime[run each benchmark during n seconds]:duration" \ "-benchmem[print memory allocation stats]" \
"-benchtime[run each benchmark until taking this long]:duration" \
"-blockprofile[write goroutine blocking profile to file]:file" \
"-blockprofilerate[set sampling rate of goroutine blocking profile]:number" \
"-timeout[kill test after that duration]:duration" \ "-timeout[kill test after that duration]:duration" \
"-cpuprofile[write CPU profile to file]:file:_files" \ "-cpuprofile[write CPU profile to file]:file:_files" \
"-memprofile[write heap profile to file]:file:_files" \ "-memprofile[write heap profile to file]:file:_files" \
@ -97,7 +107,7 @@ __go_tool_complete() {
help) help)
_values "${commands[@]}" \ _values "${commands[@]}" \
'gopath[GOPATH environment variable]' \ 'gopath[GOPATH environment variable]' \
'importpath[description of import paths]' \ 'packages[description of package lists]' \
'remote[remote import path syntax]' \ 'remote[remote import path syntax]' \
'testflag[description of testing flags]' \ 'testflag[description of testing flags]' \
'testfunc[description of testing functions]' 'testfunc[description of testing functions]'

View file

@ -20,6 +20,7 @@ _1st_arguments=(
'bundle:create pybundles (archives containing multiple packages)' 'bundle:create pybundles (archives containing multiple packages)'
'freeze:output all currently installed packages (exact versions) to stdout' 'freeze:output all currently installed packages (exact versions) to stdout'
'help:show available commands' 'help:show available commands'
'show:show information about installed packages'
'install:install packages' 'install:install packages'
'search:search PyPI' 'search:search PyPI'
'uninstall:uninstall packages' 'uninstall:uninstall packages'
@ -76,4 +77,7 @@ case "$words[1]" in
uninstall) uninstall)
_pip_installed _pip_installed
_wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;; _wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
show)
_pip_installed
_wanted installed_pkgs expl 'installed packages' compadd -a installed_pkgs ;;
esac esac

View file

@ -51,6 +51,7 @@ alias rds='rake db:seed'
alias rdd='rake db:drop' alias rdd='rake db:drop'
alias rdtc='rake db:test:clone' alias rdtc='rake db:test:clone'
alias rdtp='rake db:test:prepare' alias rdtp='rake db:test:prepare'
alias rdmtc='rake db:migrate db:test:clone'
alias rlc='rake log:clear' alias rlc='rake log:clear'
alias rn='rake notes' alias rn='rake notes'

View file

@ -10,12 +10,18 @@ FOUND_RBENV=0
rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv") rbenvdirs=("$HOME/.rbenv" "/usr/local/rbenv" "/opt/rbenv")
if _homebrew-installed && _rbenv-from-homebrew-installed ; then if _homebrew-installed && _rbenv-from-homebrew-installed ; then
rbenvdirs=($(brew --prefix rbenv) "${rbenvdirs[@]}") rbenvdirs=($(brew --prefix rbenv) "${rbenvdirs[@]}")
if [[ $RBENV_ROOT = '' ]]; then
RBENV_ROOT="$HOME/.rbenv"
fi
fi fi
for rbenvdir in "${rbenvdirs[@]}" ; do for rbenvdir in "${rbenvdirs[@]}" ; do
if [ -d $rbenvdir/bin -a $FOUND_RBENV -eq 0 ] ; then if [ -d $rbenvdir/bin -a $FOUND_RBENV -eq 0 ] ; then
FOUND_RBENV=1 FOUND_RBENV=1
export RBENV_ROOT=$rbenvdir if [[ $RBENV_ROOT = '' ]]; then
RBENV_ROOT=$rbenvdir
fi
export RBENV_ROOT
export PATH=${rbenvdir}/bin:$PATH export PATH=${rbenvdir}/bin:$PATH
eval "$(rbenv init --no-rehash - zsh)" eval "$(rbenv init --no-rehash - zsh)"

View file

@ -1,25 +1,32 @@
# Sublime Text 2 Aliases # Sublime Text 2 Aliases
local _sublime_darwin_paths > /dev/null 2>&1
_sublime_darwin_paths=(
"/usr/local/bin/subl"
"$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"
"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
)
if [[ $('uname') == 'Linux' ]]; then if [[ $('uname') == 'Linux' ]]; then
if [ -f '/usr/bin/sublime_text' ]; then local _sublime_linux_paths > /dev/null 2>&1
st_run() { nohup /usr/bin/sublime_text $@ > /dev/null & } _sublime_linux_paths=(
else "$HOME/bin/sublime_text"
st_run() { nohup /usr/bin/sublime-text $@ > /dev/null & } "/opt/sublime_text/sublime_text"
fi "/usr/bin/sublime_text"
alias st=st_run "/usr/local/bin/sublime_text"
)
for _sublime_path in $_sublime_linux_paths; do
if [[ -a $_sublime_path ]]; then
st_run() { $_sublime_path $@ >/dev/null 2>&1 &| }
alias st=st_run
break
fi
done
elif [[ $('uname') == 'Darwin' ]]; then elif [[ $('uname') == 'Darwin' ]]; then
local _sublime_darwin_paths > /dev/null 2>&1
_sublime_darwin_paths=(
"/usr/local/bin/subl"
"/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl"
)
for _sublime_path in $_sublime_darwin_paths; do for _sublime_path in $_sublime_darwin_paths; do
if [[ -a $_sublime_path ]]; then if [[ -a $_sublime_path ]]; then

View file

@ -0,0 +1,73 @@
# vim:ft=zsh ts=2 sw=2 sts=2 et
#
# Faster alternative to the current SVN plugin implementation.
#
# Works with svn 1.6, 1.7, 1.8.
# Use `svn_prompt_info` method to enquire the svn data.
# It's faster because his efficient use of svn (single svn call) which saves a lot on a huge codebase
# It displays the current status of the local files (added, deleted, modified, replaced, or else...)
#
# Use as a drop-in replacement of the svn plugin not as complementary plugin
function svn_prompt_info() {
local info
info=$(svn info 2>&1) || return 1; # capture stdout and stderr
local repo_need_upgrade=$(svn_repo_need_upgrade $info)
if [[ -n $repo_need_upgrade ]]; then
printf '%s%s%s%s%s%s%s\n' \
$ZSH_PROMPT_BASE_COLOR \
$ZSH_THEME_SVN_PROMPT_PREFIX \
$ZSH_PROMPT_BASE_COLOR \
$repo_need_upgrade \
$ZSH_PROMPT_BASE_COLOR \
$ZSH_THEME_SVN_PROMPT_SUFFIX \
$ZSH_PROMPT_BASE_COLOR
else
printf '%s%s%s %s%s:%s%s%s%s%s' \
$ZSH_PROMPT_BASE_COLOR \
$ZSH_THEME_SVN_PROMPT_PREFIX \
\
"$(svn_status_info $info)" \
$ZSH_PROMPT_BASE_COLOR \
\
$ZSH_THEME_BRANCH_NAME_COLOR \
$(svn_current_branch_name $info) \
$ZSH_PROMPT_BASE_COLOR \
\
$(svn_current_revision $info) \
$ZSH_PROMPT_BASE_COLOR \
\
$ZSH_THEME_SVN_PROMPT_SUFFIX \
$ZSH_PROMPT_BASE_COLOR
fi
}
function svn_repo_need_upgrade() {
grep -q "E155036" <<< ${1:-$(svn info 2> /dev/null)} && \
echo "E155036: upgrade repo with svn upgrade"
}
function svn_current_branch_name() {
grep '^URL:' <<< "${1:-$(svn info 2> /dev/null)}" | egrep -o '(tags|branches)/[^/]+|trunk'
}
function svn_repo_root_name() {
grep '^Repository\ Root:' <<< "${1:-$(svn info 2> /dev/null)}" | sed 's#.*/##'
}
function svn_current_revision() {
echo "${1:-$(svn info 2> /dev/null)}" | sed -n 's/Revision: //p'
}
function svn_status_info() {
local svn_status_string="$ZSH_THEME_SVN_PROMPT_CLEAN"
local svn_status="$(svn status 2> /dev/null)";
if grep -E '^\s*A' &> /dev/null <<< $svn_status; then svn_status_string="$svn_status_string ${ZSH_THEME_SVN_PROMPT_ADDITIONS:-+}"; fi
if grep -E '^\s*D' &> /dev/null <<< $svn_status; then svn_status_string="$svn_status_string ${ZSH_THEME_SVN_PROMPT_DELETIONS:-}"; fi
if grep -E '^\s*M' &> /dev/null <<< $svn_status; then svn_status_string="$svn_status_string ${ZSH_THEME_SVN_PROMPT_MODIFICATIONS:-}"; fi
if grep -E '^\s*[R~]' &> /dev/null <<< $svn_status; then svn_status_string="$svn_status_string ${ZSH_THEME_SVN_PROMPT_REPLACEMENTS:-}"; fi
if grep -E '^\s*\?' &> /dev/null <<< $svn_status; then svn_status_string="$svn_status_string ${ZSH_THEME_SVN_PROMPT_UNTRACKED:-?}"; fi
if grep -E '^\s*[CI!L]' &> /dev/null <<< $svn_status; then svn_status_string="$svn_status_string ${ZSH_THEME_SVN_PROMPT_DIRTY:-'!'}"; fi
echo $svn_status_string
}

View file

@ -1,48 +1,68 @@
#compdef wd.sh #compdef wd
zstyle ":completion:*:descriptions" format "%B%d%b" zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion::complete:wd:*:commands' group-name commands
zstyle ':completion::complete:wd:*:warp_points' group-name warp_points
zstyle ':completion::complete:wd::' list-grouped
CONFIG=$HOME/.warprc # Call `_wd()` when when trying to complete the command `wd`
local -a main_commands zmodload zsh/mapfile
main_commands=( function _wd() {
add:'Adds the current working directory to your warp points' local ret=1
#add'\!':'Overwrites existing warp point' # TODO: Fix local CONFIG=$HOME/.warprc
rm:'Removes the given warp point'
ls:'Outputs all stored warp points'
show:'Outputs warp points to current directory'
)
local -a points # Stolen from
while read line # http://stackoverflow.com/questions/9000698/completion-when-program-has-sub-commands
do
points+=$(awk "{ gsub(/\/Users\/$USER|\/home\/$USER/,\"~\"); print }" <<< $line)
done < $CONFIG
_wd() # local curcontext="$curcontext" state line
{ # typeset -A opt_args
# init variables
local curcontext="$curcontext" state line
typeset -A opt_args
# init state local -a commands
_arguments \ local -a warp_points
'1: :->command' \ warp_points=( "${(f)mapfile[$CONFIG]}" )
'2: :->argument' # LIST="${mapfile[$FNAME]}" # Not required unless stuff uses it
case $state in commands=(
command) 'add:Adds the current working directory to your warp points'
compadd "$@" add rm ls show 'add!:Overwrites existing warp point'
_describe -t warp-points 'Warp points:' points && ret=0 'rm:Removes the given warp point'
;; 'ls:Outputs all stored warp points'
argument) 'show:Outputs all warp points that point to the current directory'
case $words[2] in 'help:Show this extremely helpful text'
rm|add!) '..:Go back to last directory'
_describe -t warp-points 'warp points' points && ret=0 )
;;
*) _arguments -C \
esac '1: :->first_arg' \
esac '2: :->second_arg' && ret=0
case $state in
first_arg)
_describe -t warp_points "Warp points" warp_points && ret=0
_describe -t commands "Commands" commands && ret=0
;;
second_arg)
case $words[2] in
add\!|rm)
_describe -t points "Warp points" warp_points && ret=0
;;
add)
_message 'Write the name of your warp point' && ret=0
;;
esac
;;
esac
return $ret
} }
_wd "$@" _wd "$@"
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et

View file

@ -6,4 +6,6 @@
# #
# @github.com/mfaerevaag/wd # @github.com/mfaerevaag/wd
alias wd='. $ZSH/plugins/wd/wd.sh' wd() {
. $ZSH/plugins/wd/wd.sh
}

View file

@ -50,12 +50,12 @@ wd_warp()
wd_print_msg $YELLOW "Warping to current directory?" wd_print_msg $YELLOW "Warping to current directory?"
else else
(( n = $#1 - 1 )) (( n = $#1 - 1 ))
wd_print_msg $BLUE "Warping..." #wd_print_msg $BLUE "Warping..."
cd -$n > /dev/null cd -$n > /dev/null
fi fi
elif [[ ${points[$1]} != "" ]] elif [[ ${points[$1]} != "" ]]
then then
wd_print_msg $BLUE "Warping..." #wd_print_msg $BLUE "Warping..."
cd ${points[$1]} cd ${points[$1]}
else else
wd_print_msg $RED "Unkown warp point '$1'" wd_print_msg $RED "Unkown warp point '$1'"
@ -64,16 +64,16 @@ wd_warp()
wd_add() wd_add()
{ {
if [[ $1 =~ "^\.+$" ]] if [[ $2 =~ "^\.+$" || $2 =~ "^\s*$" ]]
then then
wd_print_msg $RED "Illeagal warp point (see README)." wd_print_msg $RED "Illegal warp point (see README)."
elif [[ ${points[$1]} == "" ]] || $2 elif [[ ${points[$2]} == "" ]] || $1
then then
wd_remove $1 > /dev/null wd_remove $2 > /dev/null
print "$1:$PWD" >> $CONFIG print "$2:$PWD" >> $CONFIG
wd_print_msg $GREEN "Warp point added" wd_print_msg $GREEN "Warp point added"
else else
wd_print_msg $YELLOW "Warp point '$1' alredy exists. Use 'add!' to overwrite." wd_print_msg $YELLOW "Warp point '$2' already exists. Use 'add!' to overwrite."
fi fi
} }
@ -83,7 +83,9 @@ wd_remove()
then then
if wd_tmp=`sed "/^$1:/d" $CONFIG` if wd_tmp=`sed "/^$1:/d" $CONFIG`
then then
echo $wd_tmp > $CONFIG # `>!` forces overwrite
# we need this if people use `setopt NO_CLOBBER`
echo $wd_tmp >! $CONFIG
wd_print_msg $GREEN "Warp point removed" wd_print_msg $GREEN "Warp point removed"
else else
wd_print_msg $RED "Warp point unsuccessfully removed. Sorry!" wd_print_msg $RED "Warp point unsuccessfully removed. Sorry!"
@ -131,9 +133,9 @@ wd_print_usage()
print "\nCommands:" print "\nCommands:"
print "\t add \t Adds the current working directory to your warp points" print "\t add \t Adds the current working directory to your warp points"
print "\t add! \t Overwrites existing warp point" print "\t add! \t Overwrites existing warp point"
print "\t remove Removes the given warp point" print "\t rm \t Removes the given warp point"
print "\t show \t Outputs warp points to current directory" print "\t show \t Outputs warp points to current directory"
print "\t list \t Outputs all stored warp points" print "\t ls \t Outputs all stored warp points"
print "\t help \t Show this extremely helpful text" print "\t help \t Show this extremely helpful text"
} }
@ -141,7 +143,7 @@ wd_print_usage()
## run ## run
# get opts # get opts
args=`getopt -o a:r:lhs -l add:,remove:,list,help,show -- $*` args=`getopt -o a:r:lhs -l add:,rm:,ls,help,show -- $*`
# check if no arguments were given # check if no arguments were given
if [[ $? -ne 0 || $#* -eq 0 ]] if [[ $? -ne 0 || $#* -eq 0 ]]
@ -161,49 +163,40 @@ else
for i for i
do do
case "$i" case "$i"
in in
-a|--add|add) -a|--add|add)
wd_add $2 false wd_add false $2
shift
shift
break break
;; ;;
-a!|--add!|add!) -a!|--add!|add!)
wd_add $2 true wd_add true $2
shift
shift
break break
;; ;;
-r|--remove|rm) -r|--remove|rm)
wd_remove $2 wd_remove $2
shift
shift
break break
;; ;;
-l|--list|ls) -l|--list|ls)
wd_list_all wd_list_all
shift
break break
;; ;;
-h|--help|help) -h|--help|help)
wd_print_usage wd_print_usage
shift
break break
;; ;;
-s|--show|show) -s|--show|show)
wd_show wd_show
shift
break break
;; ;;
*) *)
wd_warp $i wd_warp $i
shift
break break
;; ;;
--) --)
shift; break;; break
esac ;;
esac
done done
fi fi
@ -211,6 +204,6 @@ fi
## garbage collection ## garbage collection
# if not, next time warp will pick up variables from this run # if not, next time warp will pick up variables from this run
# remember, there's no sub shell # remember, there's no sub shell
points="" unset points
args="" unset args
unhash -d val &> /dev/null # fixes issue #1 unset val &> /dev/null # fixes issue #1

View file

@ -16,3 +16,4 @@ function xcsel {
alias xcb='xcodebuild' alias xcb='xcodebuild'
alias xcp='xcode-select --print-path' alias xcp='xcode-select --print-path'
alias simulator='open $(xcode-select -p)/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app'

View file

@ -0,0 +1,17 @@
# Yii basic command completion
_yii_get_command_list () {
protected/yiic | awk '/^ - [a-z]+/ { print $2 }'
}
_yii () {
if [ -f protected/yiic ]; then
compadd `_yii_get_command_list`
fi
}
compdef _yii protected/yiic
compdef _yii yiic
# Aliases
alias yiic='protected/yiic'

View file

@ -8,8 +8,6 @@
# Created on: June 19, 2012 # Created on: June 19, 2012
# Last modified on: June 20, 2012 # Last modified on: June 20, 2012
if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="green"; fi if [ $UID -eq 0 ]; then NCOLOR="red"; else NCOLOR="green"; fi
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})" local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
@ -27,7 +25,12 @@ eval my_gray='$FG[237]'
eval my_orange='$FG[214]' eval my_orange='$FG[214]'
# right prompt # right prompt
RPROMPT='$(virtualenv_prompt_info)$my_gray%n@%m%{$reset_color%}%' if type "virtualenv_prompt_info" > /dev/null
then
RPROMPT='$(virtualenv_prompt_info)$my_gray%n@%m%{$reset_color%}%'
else
RPROMPT='$my_gray%n@%m%{$reset_color%}%'
fi
# git settings # git settings
ZSH_THEME_GIT_PROMPT_PREFIX="$FG[075](branch:" ZSH_THEME_GIT_PROMPT_PREFIX="$FG[075](branch:"

View file

@ -6,7 +6,7 @@
# # README # # README
# #
# In order for this theme to render correctly, you will need a # In order for this theme to render correctly, you will need a
# [Powerline-patched font](https://gist.github.com/1595572). # [Powerline-patched font](https://github.com/Lokaltog/powerline-fonts).
# #
# In addition, I recommend the # In addition, I recommend the
# [Solarized theme](https://github.com/altercation/solarized/) and, if you're # [Solarized theme](https://github.com/altercation/solarized/) and, if you're
@ -88,9 +88,9 @@ prompt_git() {
zstyle ':vcs_info:*' stagedstr '✚' zstyle ':vcs_info:*' stagedstr '✚'
zstyle ':vcs_info:git:*' unstagedstr '●' zstyle ':vcs_info:git:*' unstagedstr '●'
zstyle ':vcs_info:*' formats ' %u%c' zstyle ':vcs_info:*' formats ' %u%c'
zstyle ':vcs_info:*' actionformats '%u%c' zstyle ':vcs_info:*' actionformats ' %u%c'
vcs_info vcs_info
echo -n "${ref/refs\/heads\//± }${vcs_info_msg_0_}" echo -n "${ref/refs\/heads\// }${vcs_info_msg_0_%% }"
fi fi
} }

View file

@ -101,12 +101,12 @@ _1RIGHT="[%*] "
bureau_precmd () { bureau_precmd () {
_1SPACES=`get_space $_1LEFT $_1RIGHT` _1SPACES=`get_space $_1LEFT $_1RIGHT`
echo print
print -rP "$_1LEFT$_1SPACES$_1RIGHT"
} }
setopt prompt_subst setopt prompt_subst
PROMPT='$_1LEFT$_1SPACES$_1RIGHT PROMPT='> $_LIBERTY '
> $_LIBERTY '
RPROMPT='$(nvm_prompt_info) $(bureau_git_prompt)' RPROMPT='$(nvm_prompt_info) $(bureau_git_prompt)'
autoload -U add-zsh-hook autoload -U add-zsh-hook

View file

@ -32,3 +32,16 @@ PROMPT="
${git_info} \ ${git_info} \
%{$fg[white]%}[%*] %{$fg[white]%}[%*]
%{$terminfo[bold]$fg[red]%}$ %{$reset_color%}" %{$terminfo[bold]$fg[red]%}$ %{$reset_color%}"
if [[ "$(whoami)" == "root" ]]; then
PROMPT="
%{$terminfo[bold]$fg[blue]%}#%{$reset_color%} \
%{$bg[yellow]%}%{$fg[cyan]%}%n%{$reset_color%} \
%{$fg[white]%}at \
%{$fg[green]%}$(box_name) \
%{$fg[white]%}in \
%{$terminfo[bold]$fg[yellow]%}${current_dir}%{$reset_color%}\
${git_info} \
%{$fg[white]%}[%*]
%{$terminfo[bold]$fg[red]%}$ %{$reset_color%}"
fi

View file

@ -43,4 +43,4 @@ echo "\033[0;32m"' /____/ '"\033[0m
echo "\n\n \033[0;32m....is now installed.\033[0m" echo "\n\n \033[0;32m....is now installed.\033[0m"
echo "\n\n \033[0;32mPlease look over the ~/.zshrc file to select plugins, themes, and options.\033[0m" echo "\n\n \033[0;32mPlease look over the ~/.zshrc file to select plugins, themes, and options.\033[0m"
/usr/bin/env zsh /usr/bin/env zsh
source ~/.zshrc . ~/.zshrc