Git shell 函数(用于别名)在 bash 中工作,选项卡完成但在 Zsh 中不工作

Git shell function (for aliasing) worked in bash with tab complete but not working in Zsh

我在 bash 中成功使用但在 Zsh 中不再有效的别名看起来像这样

.zshrc(之前是 .bashrc

# custom git completions 
_git_a ()
{
    _git_add
}
_git_b ()
{
    _git_branch
}
_git_c ()
{
    _git_commit
}
_git_co () 
{
    _git_checkout 
}
.
.
.

# git alias function
g ()
{
    arg1=
    shift
    case "$arg1" in
        a)
            eval git add $@;;
        b)
            eval git branch $@;;
        c)
            eval git commit -m \"\";;
        co)
            eval git checkout $@;;
        .
        .
        .
        *)
            eval git $arg1 $@;;
    esac
}

zstyle ':completion:*:*:git:*' script ~/.git-completions-mingit.bash
autoload -Uz compinit && compinit -u
source ~/.mingit.sh
compdef g='git'

以前(在 bash 中)在别名中键入一些内容,例如

g co<TAB><TAB>

会导致与

相同的行为
git checkout<TAB><TAB>

但现在(在 Zsh 中)结果是 g co<TAB><TAB> 循环遍历目录中的文件夹和文件。有没有办法让 g co 或其他 g 命令的制表符补全在制表符补全时与 git ... 相同?

这可以按照git-completion.zshhttps://github.com/git/git/blob/master/contrib/completion/git-completion.zsh)中的说明解决:

# For example, create a directory '~/.zsh/', copy this file to '~/.zsh/_git',
# and then add the following to your ~/.zshrc file:
#
#  fpath=(~/.zsh $fpath)
#
# You need git's bash completion script installed. By default bash-completion's
# location will be used (e.g. pkg-config --variable=completionsdir bash-completion).