completion: zsh: refactor command completion
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Oct 27, 2020 at 20:07 UTC
9a397ea5ad59e64ff6eebfd1d7dad43aac790e0a
1 file changed
+16
-4
contrib/completion/git-completion.zsh
+16
-4
@@ -134,20 +134,32 @@ __gitcomp_file_direct ()
134
__gitcomp_file "$1" ""
135
}
136
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
+
151
__git_zsh_bash_func ()
152
{
153
emulate -L ksh
154
155
local command=$1
156
143
- local completion_func="_git_${command//-/_}"
144
- declare -f $completion_func >/dev/null && $completion_func && return
157
+ __git_complete_command "$command" && return
158
159
local expansion=$(__git_aliased_command "$command")
160
if [ -n "$expansion" ]; then
161
words[1]=$expansion
149
- completion_func="_git_${expansion//-/_}"
150
- declare -f $completion_func >/dev/null && $completion_func
162
+ __git_complete_command "$expansion"
163
fi
164
}
165