From: Felipe Contreras Date: Wed, 28 Oct 2020 02:07:04 +0000 (-0600) Subject: completion: zsh: refactor command completion X-Git-Tag: v2.30.0-rc0~105^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a397ea5ad59e64ff6eebfd1d7dad43aac790e0a;p=thirdparty%2Fgit.git completion: zsh: refactor command completion Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 60efddb4a9..858864f3fb 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -134,20 +134,32 @@ __gitcomp_file_direct () __gitcomp_file "$1" "" } +__git_complete_command () +{ + emulate -L zsh + + local command="$1" + local completion_func="_git_${command//-/_}" + if (( $+functions[$completion_func] )); then + emulate ksh -c $completion_func + return 0 + else + return 1 + fi +} + __git_zsh_bash_func () { emulate -L ksh local command=$1 - local completion_func="_git_${command//-/_}" - declare -f $completion_func >/dev/null && $completion_func && return + __git_complete_command "$command" && return local expansion=$(__git_aliased_command "$command") if [ -n "$expansion" ]; then words[1]=$expansion - completion_func="_git_${expansion//-/_}" - declare -f $completion_func >/dev/null && $completion_func + __git_complete_command "$expansion" fi }