我为git定义了一个别名,定义为
alias g=git使用这个以及我的zsh和抗原设置,g具有与git相同的自动完成功能。
但是,当我用函数替换g时,默认情况下会显示git状态。
g() {
if [ "$#" -eq 0 ]; then
git status --short --branch
else
git "$@"
fi
}当然,这已经不起作用了。git-all函数在子目录中的所有存储库中运行相同的git命令也是如此。
git-all() {
if [ "$#" -eq 0 ]; then
find . -maxdepth 3 -type d -name .git -execdir echo \; -execdir pwd \; -execdir git status --short --branch \;
else
find . -maxdepth 3 -type d -name .git -execdir echo \; -execdir pwd \; -execdir git "$@" \;
fi
}
alias ga='git-all'我希望完成所有这些,g、git-all和ga,就像git一样。
文档说
如果您希望一个命令(比如cmd1 )具有与另一个命令相同的完成性,比如已经为其定义完成的cmd2,则可以执行以下操作: compdef cmd1=cmd2
所以,我打字
compdef git-all=git在我当前的zsh会话中,它可以工作!好的。
因此,我在我的抗原设置之后,在我的.zshrc中放置了zsh-users/zsh-completions,并且在我的别名和函数定义之后,使用了D19。
if [ -f ~/.antigenrc ]; then
source ~/.antigenrc
fi
if [ -f ~/.sh_aliases ]; then
source ~/.sh_aliases
fi
compdef g=git
compdef ga=git
compdef git-all=git
antigen apply我的抗原是这样的:
source /usr/share/zsh-antigen/antigen.zsh
antigen use oh-my-zsh
antigen bundle gradle/gradle-completion
antigen bundle command-not-found
antigen bundle MikeDacre/cdbk
antigen bundle zsh-users/zsh-completions
antigen bundle zsh-users/zsh-syntax-highlighting
antigen theme ys我开始了一个新的弹壳。现在完工不起作用了。
这怎么可能呢?一个交互式的zsh读取.zshrc (如果我在其中放置一个echo,我会看到输出)。如果我把compdef放在抗原设置之前,我会得到关于compdef没有被定义的错误,但是当它们结束时,它们不会显示错误,它们只是不起作用。也许抗原是在做一些奇怪的事情,但即便如此,完成也是在抗原设置之后定义的,所以抗原不应该把它们搞砸?
我还尝试将_git 2>/dev/null添加到我的.zshrc中,如建议的这里,或者按照建议的这里使用compdef '_dispatch git git' g,但都没有效果。
我的zsh版本是5.8。
发布于 2022-01-22 04:39:48
正如Github发行评论中所建议的那样,解决方法(未知后果)需要在antigen.zsh而不是.antigen/init.zsh中注释下面一行(因为每次加载抗原时都生成init.zsh )
# autoload -Uz add-zsh-hook; add-zsh-hook precmd _antigen_compinit
# compdef () {}https://unix.stackexchange.com/questions/670676
复制相似问题