From: Felipe Contreras Date: Sun, 25 Oct 2020 03:13:35 GMT Subject: [PATCH v2 21/29] completion: zsh: refactor command completion Message-ID: <20201025031343.346913-22-felipe.contreras@gmail.com> In-Reply-To: <20201025031343.346913-1-felipe.contreras@gmail.com> Signed-off-by: Felipe Contreras --- contrib/completion/git-completion.zsh | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/contrib/completion/git-completion.zsh b/contrib/completion/git-completion.zsh index 179e8ff07d..702ce8db25 100644 --- a/contrib/completion/git-completion.zsh +++ b/contrib/completion/git-completion.zsh @@ -127,20 +127,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 } -- 2.29.0