Skip to content

Commit 9a397ea

Browse files
felipecgitster
authored andcommitted
completion: zsh: refactor command completion
Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 46af9b3 commit 9a397ea

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

contrib/completion/git-completion.zsh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,32 @@ __gitcomp_file_direct ()
134134
__gitcomp_file "$1" ""
135135
}
136136

137+
__git_complete_command ()
138+
{
139+
emulate -L zsh
140+
141+
local command="$1"
142+
local completion_func="_git_${command//-/_}"
143+
if (( $+functions[$completion_func] )); then
144+
emulate ksh -c $completion_func
145+
return 0
146+
else
147+
return 1
148+
fi
149+
}
150+
137151
__git_zsh_bash_func ()
138152
{
139153
emulate -L ksh
140154

141155
local command=$1
142156

143-
local completion_func="_git_${command//-/_}"
144-
declare -f $completion_func >/dev/null && $completion_func && return
157+
__git_complete_command "$command" && return
145158

146159
local expansion=$(__git_aliased_command "$command")
147160
if [ -n "$expansion" ]; then
148161
words[1]=$expansion
149-
completion_func="_git_${expansion//-/_}"
150-
declare -f $completion_func >/dev/null && $completion_func
162+
__git_complete_command "$expansion"
151163
fi
152164
}
153165

0 commit comments

Comments
 (0)