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 make a copy of it in
15 # ~/.zsh/ directory as ~/.zsh/git-completion.zsh and then add the following
16 # to your ~/.zshrc file:
18 # fpath=(~/.zsh $fpath)
26 zstyle
-T ':completion:*:*:git:*' tag-order
&& \
27 zstyle
':completion:*:*:git:*' tag-order
'common-commands'
29 zstyle
-s ":completion:*:*:git:*" script script
30 if [ -z "$script" ]; then
34 $
(dirname ${funcsourcetrace[1]%:*})/git-completion.bash
35 '/etc/bash_completion.d/git' # fedora, old debian
36 '/usr/share/bash-completion/completions/git' # arch, ubuntu, new debian
37 '/usr/share/bash-completion/git' # gentoo
39 for e
in $locations; do
40 test -f $e && script="$e" && break
43 GIT_SOURCING_ZSH_COMPLETION
=y .
"$script"
49 local cur_
="${3-$cur}"
66 compadd
-Q -S '' -p "${2-}" -a -- array
&& _ret
=0
77 compadd
-Q -- ${=1} && _ret
=0
86 compadd
-Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
89 __gitcomp_nl_append ()
94 compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret
=0
97 __gitcomp_file_direct
()
103 compadd
-f -- ${=1} && _ret
=0
112 compadd
-p "${2-}" -f -- ${=1} && _ret
=0
115 __git_zsh_bash_func
()
121 local completion_func
="_git_${command//-/_}"
122 declare -f $completion_func >/dev
/null
&& $completion_func && return
124 local expansion
=$
(__git_aliased_command
"$command")
125 if [ -n "$expansion" ]; then
127 completion_func
="_git_${expansion//-/_}"
128 declare -f $completion_func >/dev
/null
&& $completion_func
132 __git_zsh_cmd_common
()
136 add
:'add file contents to the index'
137 bisect
:'find by binary search the change that introduced a bug'
138 branch
:'list, create, or delete branches'
139 checkout
:'checkout a branch or paths to the working tree'
140 clone
:'clone a repository into a new directory'
141 commit
:'record changes to the repository'
142 diff:'show changes between commits, commit and working tree, etc'
143 fetch
:'download objects and refs from another repository'
144 grep:'print lines matching a pattern'
145 init
:'create an empty Git repository or reinitialize an existing one'
146 log
:'show commit logs'
147 merge
:'join two or more development histories together'
148 mv:'move or rename a file, a directory, or a symlink'
149 pull
:'fetch from and merge with another repository or a local branch'
150 push
:'update remote refs along with associated objects'
151 rebase
:'forward-port local commits to the updated upstream head'
152 reset:'reset current HEAD to the specified state'
153 restore
:'restore working tree files'
154 rm:'remove files from the working tree and from the index'
155 show
:'show various types of objects'
156 status
:'show the working tree status'
157 switch
:'switch branches'
158 tag
:'create, list, delete or verify a tag object signed with GPG')
159 _describe
-t common-commands
'common commands' list
&& _ret
=0
162 __git_zsh_cmd_alias
()
165 list
=(${${${(0)"$(git config -z --get-regexp '^alias\.')"}#alias.}%$
'\n'*})
166 _describe
-t alias-commands
'aliases' list $
* && _ret
=0
172 emulate ksh
-c __git_compute_all_commands
173 list
=( ${=__git_all_commands} )
174 _describe
-t all-commands
'all commands' list
&& _ret
=0
179 local curcontext
="$curcontext" state state_descr line
183 orig_words
=( ${words[@]} )
186 '(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \
187 '(-p --paginate)--no-pager[do not pipe git output into a pager]' \
188 '--git-dir=-[set the path to the repository]: :_directories' \
189 '--bare[treat the repository as a bare repository]' \
190 '(- :)--version[prints the git suite version]' \
191 '--exec-path=-[path to where your core git programs are installed]:: :_directories' \
192 '--html-path[print the path where git''s HTML documentation is installed]' \
193 '--info-path[print the path where the Info files are installed]' \
194 '--man-path[print the manpath (see `man(1)`) for the man pages]' \
195 '--work-tree=-[set the path to the working tree]: :_directories' \
196 '--namespace=-[set the git namespace]' \
197 '--no-replace-objects[do not use replacement refs to replace git objects]' \
198 '(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \
200 '(-)*:: :->arg' && return
205 'alias-commands:alias:__git_zsh_cmd_alias' \
206 'common-commands:common:__git_zsh_cmd_common' \
207 'all-commands:all:__git_zsh_cmd_all' && _ret
=0
210 local command="${words[1]}" __git_dir
212 if (( $
+opt_args
[--bare] )); then
215 __git_dir
=${opt_args[--git-dir]}
218 (( $
+opt_args
[--help] )) && command='help'
220 words
=( ${orig_words[@]} )
222 __git_zsh_bash_func
$command
232 cur
=${words[CURRENT]}
233 prev
=${words[CURRENT-1]}
236 if (( $
+functions
[__
${service}_zsh_main
] )); then
237 __
${service}_zsh_main
239 emulate ksh
-c __
${service}_main
242 let _ret
&& _default
&& _ret
=0