]> git.ipfire.org Git - thirdparty/git.git/commitdiff
completion: zsh: fix for command aliasing
authorFelipe Contreras <felipe.contreras@gmail.com>
Wed, 28 Oct 2020 02:06:51 +0000 (20:06 -0600)
committerJunio C Hamano <gitster@pobox.com>
Wed, 28 Oct 2020 21:30:59 +0000 (14:30 -0700)
A lot of people want to define aliases like gc='git commit', and zsh
allows that (when not using 'complete_aliases'), but we need to handle
services that call a function other than the main one.

With this patch we can do:

  compdef _git gc=git_commit

Additionally, add compatibility for Zsh Git functions which have the
form git-commit (with dash, not underscore).

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.zsh

index ccf384ba35e6ef42822b50291598b5c418c1dce0..f524c6042a26afd0a7ab491e1f1c0273946df3ac 100644 (file)
@@ -243,8 +243,12 @@ _git ()
 
        if (( $+functions[__${service}_zsh_main] )); then
                __${service}_zsh_main
-       else
+       elif (( $+functions[__${service}_main] )); then
                emulate ksh -c __${service}_main
+       elif (( $+functions[_${service}] )); then
+               emulate ksh -c _${service}
+       elif (( $+functions[_${service//-/_}] )); then
+               emulate ksh -c _${service//-/_}
        fi
 
        let _ret && _default && _ret=0