简体   繁体   English

zsh 上的 git 完成未列出不明确的选项(在 macOS 上)

[英]git completion on zsh not listing ambiguous options (on macOS)

My machine is a M1 Mac mini running Big Sur.我的机器是运行 Big Sur 的 M1 Mac mini。

I am trying to get git completion to work in the default terminal which uses a zsh shell.我试图让 git 完成在使用 zsh shell 的默认终端中工作。

This is what I am trying and expecting. 这是我正在尝试和期待的。 Screenshot below.截图如下。

zsh 的 git 完成

I am able to get completion to work, but not exactly as described here.我能够完成工作,但与此处描述的不完全一样。

Basically, if I type git che Tab that directly converts into git checkout instead of giving/listing the options of all the git commands starting with "che" (as shown in the screenshot above.)基本上,如果我输入git che Tab直接转换为git checkout ,而不是给出/列出所有 git 命令的选项以“che”开头(如上图所示)。

Any further presses of Tab simply result in cycling through various branches, but the checkout doesn't change at all. Tab的任何进一步按下只会导致在各个分支之间循环,但checkout根本不会改变。

I have tried multiple ways like我尝试了多种方法,例如

But none seem to work..但似乎没有一个工作..

What am I doing wrong?我究竟做错了什么?

(by the way, I am ok even if the helpful suggestions (in above screenshot) are not displayed. But the completion should allow me to see a list of all possible ambiguous options and to cycle through them.) (顺便说一句,即使没有显示有用的建议(在上面的屏幕截图中),我也可以。但是完成应该允许我看到所有可能的模棱两可选项的列表并循环浏览它们。)

Did you install Git through Homebrew ?您是否通过Homebrew安装了 Git ? If so, then it also installed the completion bundled with Git, which is a simple port of its Bash completion, which then overrides Zsh's own much more sophisticated Git completion.如果是这样,那么它还安装了与 Git 捆绑在一起的完成,这是 Bash 完成的简单端口,然后覆盖 Zsh 自己更复杂的 Git 完成。

At least two issues and two PRs have been filed with Homebrew to make installing the completion shipped with the Git formula to be optional or remove it altogether, but its maintainer refuses to do so, because he feels using this Bash-style completion in Zsh is good enough for him.至少有两个问题两个PR已向 Homebrew 提交,以使安装 Git 公式附带的补全成为可选或完全删除它,但其维护者拒绝这样做,因为他觉得在 Zsh 中使用这种 Bash 样式补全是对他来说已经足够好了。 His argument is basically that since it ships with Git, it's the official completion and it should override Zsh's own (much better) Git completion.他的论点基本上是,因为它附带 Git,所以它是正式的完成,它应该覆盖 Zsh 自己的(好多了)Git 完成。 As to why this inferior completion is even maintained in the Git repo, when the Git manual itself recommends using Zsh's completion instead, I have no idea.至于为什么在 Git 存储库中甚至维护这种劣质完成,当 Git 手册本身建议使用 Zsh 的完成时,我不知道。 I guess that's open source for you.我想这对你来说是开源的。 ♂️ ♂️

The only reliable way I've found to work around this is to put the following line in one's .zshrc file:我发现解决此问题的唯一可靠方法是将以下行放在一个人的.zshrc文件中:

rm -f $HOMEBREW_PREFIX/share/zsh/site-functions/_git

This will cause Zsh's own completion function for Git to be used instead, which gives the much nicer output in the screenshot you posted.这将导致使用 Zsh 自己的完成 function 代替 Git,这在您发布的屏幕截图中提供了更好的 output。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM