Skip to content

Commit 01449e3

Browse files
committed
Merge branch 'maint'
* maint: complete: zsh: use zsh completion for the main cmd complete: zsh: trivial simplification git-completion.bash: complete branch.*.rebase as boolean git-completion.bash: add diff.submodule to config list git-completion.bash: lexical sorting for diff.statGraphWidth
2 parents 8974033 + 8301b97 commit 01449e3

File tree

2 files changed

+136
-9
lines changed

2 files changed

+136
-9
lines changed

contrib/completion/git-completion.bash

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1819,6 +1819,10 @@ _git_config ()
18191819
__gitcomp_nl "$(__git_refs)"
18201820
return
18211821
;;
1822+
branch.*.rebase)
1823+
__gitcomp "false true"
1824+
return
1825+
;;
18221826
remote.*.fetch)
18231827
local remote="${prev#remote.}"
18241828
remote="${remote%.fetch}"
@@ -1858,6 +1862,10 @@ _git_config ()
18581862
"
18591863
return
18601864
;;
1865+
diff.submodule)
1866+
__gitcomp "log short"
1867+
return
1868+
;;
18611869
help.format)
18621870
__gitcomp "man info web html"
18631871
return
@@ -2052,13 +2060,14 @@ _git_config ()
20522060
core.whitespace
20532061
core.worktree
20542062
diff.autorefreshindex
2055-
diff.statGraphWidth
20562063
diff.external
20572064
diff.ignoreSubmodules
20582065
diff.mnemonicprefix
20592066
diff.noprefix
20602067
diff.renameLimit
20612068
diff.renames
2069+
diff.statGraphWidth
2070+
diff.submodule
20622071
diff.suppressBlankEmpty
20632072
diff.tool
20642073
diff.wordRegex

contrib/completion/git-completion.zsh

Lines changed: 126 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# zsh completion wrapper for git
44
#
5+
# Copyright (c) 2012-2013 Felipe Contreras <[email protected]>
6+
#
57
# You need git's bash completion script installed somewhere, by default on the
68
# same directory as this script.
79
#
@@ -21,6 +23,9 @@ complete ()
2123
return 0
2224
}
2325

26+
zstyle -T ':completion:*:*:git:*' tag-order && \
27+
zstyle ':completion:*:*:git:*' tag-order 'common-commands'
28+
2429
zstyle -s ":completion:*:*:git:*" script script
2530
test -z "$script" && script="$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
2631
ZSH_VERSION='' . "$script"
@@ -69,17 +74,130 @@ __gitcomp_file ()
6974
compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
7075
}
7176

77+
__git_zsh_bash_func ()
78+
{
79+
emulate -L ksh
80+
81+
local command=$1
82+
83+
local completion_func="_git_${command//-/_}"
84+
declare -f $completion_func >/dev/null && $completion_func && return
85+
86+
local expansion=$(__git_aliased_command "$command")
87+
if [ -n "$expansion" ]; then
88+
completion_func="_git_${expansion//-/_}"
89+
declare -f $completion_func >/dev/null && $completion_func
90+
fi
91+
}
92+
93+
__git_zsh_cmd_common ()
94+
{
95+
local -a list
96+
list=(
97+
add:'add file contents to the index'
98+
bisect:'find by binary search the change that introduced a bug'
99+
branch:'list, create, or delete branches'
100+
checkout:'checkout a branch or paths to the working tree'
101+
clone:'clone a repository into a new directory'
102+
commit:'record changes to the repository'
103+
diff:'show changes between commits, commit and working tree, etc'
104+
fetch:'download objects and refs from another repository'
105+
grep:'print lines matching a pattern'
106+
init:'create an empty Git repository or reinitialize an existing one'
107+
log:'show commit logs'
108+
merge:'join two or more development histories together'
109+
mv:'move or rename a file, a directory, or a symlink'
110+
pull:'fetch from and merge with another repository or a local branch'
111+
push:'update remote refs along with associated objects'
112+
rebase:'forward-port local commits to the updated upstream head'
113+
reset:'reset current HEAD to the specified state'
114+
rm:'remove files from the working tree and from the index'
115+
show:'show various types of objects'
116+
status:'show the working tree status'
117+
tag:'create, list, delete or verify a tag object signed with GPG')
118+
_describe -t common-commands 'common commands' list && _ret=0
119+
}
120+
121+
__git_zsh_cmd_alias ()
122+
{
123+
local -a list
124+
list=(${${${(0)"$(git config -z --get-regexp '^alias\.')"}#alias.}%$'\n'*})
125+
_describe -t alias-commands 'aliases' list $* && _ret=0
126+
}
127+
128+
__git_zsh_cmd_all ()
129+
{
130+
local -a list
131+
emulate ksh -c __git_compute_all_commands
132+
list=( ${=__git_all_commands} )
133+
_describe -t all-commands 'all commands' list && _ret=0
134+
}
135+
136+
__git_zsh_main ()
137+
{
138+
local curcontext="$curcontext" state state_descr line
139+
typeset -A opt_args
140+
local -a orig_words
141+
142+
orig_words=( ${words[@]} )
143+
144+
_arguments -C \
145+
'(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \
146+
'(-p --paginate)--no-pager[do not pipe git output into a pager]' \
147+
'--git-dir=-[set the path to the repository]: :_directories' \
148+
'--bare[treat the repository as a bare repository]' \
149+
'(- :)--version[prints the git suite version]' \
150+
'--exec-path=-[path to where your core git programs are installed]:: :_directories' \
151+
'--html-path[print the path where git''s HTML documentation is installed]' \
152+
'--info-path[print the path where the Info files are installed]' \
153+
'--man-path[print the manpath (see `man(1)`) for the man pages]' \
154+
'--work-tree=-[set the path to the working tree]: :_directories' \
155+
'--namespace=-[set the git namespace]' \
156+
'--no-replace-objects[do not use replacement refs to replace git objects]' \
157+
'(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \
158+
'(-): :->command' \
159+
'(-)*:: :->arg' && return
160+
161+
case $state in
162+
(command)
163+
_alternative \
164+
'alias-commands:alias:__git_zsh_cmd_alias' \
165+
'common-commands:common:__git_zsh_cmd_common' \
166+
'all-commands:all:__git_zsh_cmd_all' && _ret=0
167+
;;
168+
(arg)
169+
local command="${words[1]}" __git_dir
170+
171+
if (( $+opt_args[--bare] )); then
172+
__git_dir='.'
173+
else
174+
__git_dir=${opt_args[--git-dir]}
175+
fi
176+
177+
(( $+opt_args[--help] )) && command='help'
178+
179+
words=( ${orig_words[@]} )
180+
181+
__git_zsh_bash_func $command
182+
;;
183+
esac
184+
}
185+
72186
_git ()
73187
{
74188
local _ret=1
75-
() {
76-
emulate -L ksh
77-
local cur cword prev
78-
cur=${words[CURRENT-1]}
79-
prev=${words[CURRENT-2]}
80-
let cword=CURRENT-1
81-
__${service}_main
82-
}
189+
local cur cword prev
190+
191+
cur=${words[CURRENT]}
192+
prev=${words[CURRENT-1]}
193+
let cword=CURRENT-1
194+
195+
if (( $+functions[__${service}_zsh_main] )); then
196+
__${service}_zsh_main
197+
else
198+
emulate ksh -c __${service}_main
199+
fi
200+
83201
let _ret && _default -S '' && _ret=0
84202
return _ret
85203
}

0 commit comments

Comments
 (0)