zsh中的Git tab完成抛出错误

zpf6vheq  于 2023-08-01  发布在  Git
关注(0)|答案(2)|浏览(107)

在osx上的git设置中,我努力获得制表符完成后,我得到了一些奇怪的错误,我也找不到源代码。

zsh:12: command not found: ___main
_default:compcall:12: can only be called from completion function

字符串
我不知道是什么原因导致的错误,因为一切都是正确的设置。

zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
autoload -U compinit && compinit
zmodload -i zsh/complist
source ~/.git-completion.zsh


有什么想法吗

jutyujz0

jutyujz01#

似乎git-completion.zsh不是设计为source ed。您可以将git-completion.zsh文件复制到$fpath中的某个位置,并将其重命名为_git
举例来说:(如果您决定拥有~/.zsh/functions/_git。)
首先,您可以将git-completion.zsh复制到那里,并将其重命名为_git
% mkdir -p ~/.zsh/functions && cp git-completion.zsh ~/.zsh/functions/_git
然后你可以像这样使用~/.zshrc

zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
# `compinit` scans $fpath, so do this before calling it.
fpath=(~/.zsh/functions $fpath)
autoload -Uz compinit && compinit

字符串
如果我不确定,我执行rm ~/.zcompdump以确保compinit丢弃其缓存。

kb5ga3dv

kb5ga3dv2#

mkdir -p ~/.zsh
cd ~/.zsh

字符串
获取完成脚本

curl -o git-completion.bash https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
curl -o _git https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.zsh


添加到~/.zshrc

# git completion
zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fpath=(~/.zsh $fpath)
autoload -Uz compinit && compinit


重新启动shell会话

相关问题