3 # zsh completion wrapper for git
5 # Copyright (c) 2012-2013 Felipe Contreras <felipe.contreras@gmail.com>
7 # You need git's bash completion script installed somewhere, by default it
8 # would be the location bash-completion uses.
10 # If your script is somewhere else, you can configure it on your ~/.zshrc:
12 # zstyle ':completion:*:*:git:*' script ~/.git-completion.zsh
14 # The recommended way to install this script is to copy to '~/.zsh/_git', and
15 # then add the following to your ~/.zshrc file:
17 # fpath=(~/.zsh $fpath)
25 zstyle
-T ':completion:*:*:git:*' tag-order
&& \
26 zstyle
':completion:*:*:git:*' tag-order
'common-commands'
28 zstyle
-s ":completion:*:*:git:*" script script
29 if [ -z "$script" ]; then
33 $
(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
34 '/etc/bash_completion.d/git' # fedora, old debian
35 '/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
36 '/usr/share/bash-completion/git' # gentoo
38 for e
in $locations; do
39 test -f $e && script="$e" && break
42 ZSH_VERSION
='' .
"$script"
48 local cur_
="${3-$cur}"
65 compadd
-Q -S '' -p "${2-}" -a -- array
&& _ret
=0
76 compadd
-Q -- ${=1} && _ret
=0
85 compadd
-Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
88 __gitcomp_nl_append ()
93 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret
=0
102 compadd
-Q -p "${2-}" -f -- ${=1} && _ret
=0
105 __git_zsh_bash_func
()
111 local completion_func
="_git_${command//-/_}"
112 declare -f $completion_func >/dev
/null
&& $completion_func && return
114 local expansion
=$
(__git_aliased_command
"$command")
115 if [ -n "$expansion" ]; then
117 completion_func
="_git_${expansion//-/_}"
118 declare -f $completion_func >/dev
/null
&& $completion_func
122 __git_zsh_cmd_common
()
126 add
:'add file contents to the index'
127 bisect
:'find by binary search the change that introduced a bug'
128 branch
:'list, create, or delete branches'
129 checkout
:'checkout a branch or paths to the working tree'
130 clone
:'clone a repository into a new directory'
131 commit
:'record changes to the repository'
132 diff:'show changes between commits, commit and working tree, etc'
133 fetch
:'download objects and refs from another repository'
134 grep:'print lines matching a pattern'
135 init
:'create an empty Git repository or reinitialize an existing one'
136 log
:'show commit logs'
137 merge
:'join two or more development histories together'
138 mv:'move or rename a file, a directory, or a symlink'
139 pull
:'fetch from and merge with another repository or a local branch'
140 push
:'update remote refs along with associated objects'
141 rebase
:'forward-port local commits to the updated upstream head'
142 reset:'reset current HEAD to the specified state'
143 rm:'remove files from the working tree and from the index'
144 show
:'show various types of objects'
145 status
:'show the working tree status'
146 tag
:'create, list, delete or verify a tag object signed with GPG')
147 _describe
-t common-commands
'common commands' list
&& _ret
=0
150 __git_zsh_cmd_alias
()
153 list
=(${${${(0)"$(git config -z --get-regexp '^alias\.')"}#alias.}%$
'\n'*})
154 _describe
-t alias-commands
'aliases' list $
* && _ret
=0
160 emulate ksh
-c __git_compute_all_commands
161 list
=( ${=__git_all_commands} )
162 _describe
-t all-commands
'all commands' list
&& _ret
=0
167 local curcontext
="$curcontext" state state_descr line
171 orig_words
=( ${words[@]} )
174 '(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \
175 '(-p --paginate)--no-pager[do not pipe git output into a pager]' \
176 '--git-dir=-[set the path to the repository]: :_directories' \
177 '--bare[treat the repository as a bare repository]' \
178 '(- :)--version[prints the git suite version]' \
179 '--exec-path=-[path to where your core git programs are installed]:: :_directories' \
180 '--html-path[print the path where git''s HTML documentation is installed]' \
181 '--info-path[print the path where the Info files are installed]' \
182 '--man-path[print the manpath (see `man(1)`) for the man pages]' \
183 '--work-tree=-[set the path to the working tree]: :_directories' \
184 '--namespace=-[set the git namespace]' \
185 '--no-replace-objects[do not use replacement refs to replace git objects]' \
186 '(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \
188 '(-)*:: :->arg' && return
193 'alias-commands:alias:__git_zsh_cmd_alias' \
194 'common-commands:common:__git_zsh_cmd_common' \
195 'all-commands:all:__git_zsh_cmd_all' && _ret
=0
198 local command="${words[1]}" __git_dir
200 if (( $
+opt_args
[--bare] )); then
203 __git_dir
=${opt_args[--git-dir]}
206 (( $
+opt_args
[--help] )) && command='help'
208 words
=( ${orig_words[@]} )
210 __git_zsh_bash_func
$command
220 cur
=${words[CURRENT]}
221 prev
=${words[CURRENT-1]}
224 if (( $
+functions
[__
${service}_zsh_main
] )); then
225 __
${service}_zsh_main
227 emulate ksh
-c __
${service}_main
230 let _ret
&& _default
&& _ret
=0