bash git 的 ZSH 自动完成需要大量时间,我可以关闭它或优化它吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9810327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ZSH auto completion for git takes significant amount of time, can I turn it off or optimize it?
提问by haroba
Git's tab autocompletion is useful for small projects, but I'm currently working on two big projects that use git and for these it's worse than useless. Whenever I type, say, git add forms<tab>, git takes 20 seconds or more to find the file (in this example, forms.py), and in this timespan I can't do anything else in the terminal. Is there any way to turn off the autocompletion feature, or somehow make it faster?
Git 的选项卡自动完成功能对小项目很有用,但我目前正在处理两个使用 git 的大项目,对于这些项目,它比无用更糟糕。每当我输入,比如说,git add forms<tab>git 需要 20 秒或更长时间才能找到文件(在这个例子中,forms.py),在这个时间跨度内,我无法在终端中做任何其他事情。有没有办法关闭自动完成功能,或者以某种方式使其更快?
回答by ralphtheninja
It's not git auto completing the file names, it's your shell. Do you have the same delay when doing e.g. "cat forms< tab >"?
这不是 git auto 完成文件名,而是你的 shell。您在执行“cat forms<tab>”等操作时是否有相同的延迟?
Check out this post with similar problems:
看看这篇有类似问题的帖子:
http://talkings.org/post/5236392664/zsh-and-slow-git-completion
http://talkings.org/post/5236392664/zsh-and-slow-git-completion
This post suggests adding the following to your .zshrc:
这篇文章建议将以下内容添加到您的 .zshrc 中:
__git_files () {
_wanted files expl 'local files' _files
}
EDIT: Here's the original text of that post
编辑:这是那个帖子的原文
I found many posts relating complaints about how painfully slow git auto-completion can be in large repositories. There were various suggested patches and suggestions to load the latest zsh. Maybe one of those things would work, but all I really want is for it to complete the names of branches and files as they are in the file system. I did not find any suggestions on how to get this behavior so I figured it out for myself. I thought I would share this for anyone who might benefit from it. I just added the following to my .zshrc file:
__git_files () { _wanted files expl 'local files' _files }Now I can run git commands and get near instant completion while still getting file completion similar to what ls would provide.
我发现很多帖子都抱怨大型存储库中 git 自动完成的速度有多慢。有各种建议的补丁和建议来加载最新的 zsh。也许其中一件事会起作用,但我真正想要的是它完成分支和文件的名称,就像它们在文件系统中一样。我没有找到任何关于如何获得这种行为的建议,所以我自己想出来了。我想我会把这个分享给任何可能从中受益的人。我刚刚将以下内容添加到我的 .zshrc 文件中:
__git_files () { _wanted files expl 'local files' _files }现在我可以运行 git 命令并接近即时完成,同时仍然获得类似于 ls 提供的文件完成。
回答by Mark Nadig
Finally fed up with terribly slow auto-completion in zshell and starting looking a solution. I ended up switching from 'git' to using the 'gitfast' plugin that is already installed w/ oh my zsh and am flying... https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins#gitfast
终于厌倦了 zshell 中非常缓慢的自动完成并开始寻找解决方案。我最终从'git'切换到使用已经安装的'gitfast'插件,哦,我的zsh并且正在飞行...... https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins# gitfast
回答by caveman
I have no experience with zshell, but I got this answer on another forum. You need to include this line in your .zshrc file:
我没有使用 zshell 的经验,但我在另一个论坛上得到了这个答案。您需要在 .zshrc 文件中包含这一行:
compdef -d git
回答by FelipeC
This is because Zsh comes by default with extremely bloated completion for Git. I wrote a blog postexplaining how I fixed this bloatedness, but it had to be outside of the Zsh project.
这是因为 Zsh 默认为 Git 提供极其臃肿的补全。我写了一篇博文解释了我是如何修复这种臃肿的,但它必须在 Zsh 项目之外。
The easy answer is to install Git's zsh completion, which is different than Zsh's git completion (which comes by default). Download git-completion.zsh, and place it in your ~/.zsh/_git. Then place it on your fpath:
简单的答案是安装 Git 的 zsh 完成,这与 Zsh 的 git 完成(默认情况下)不同。下载git-completion.zsh,并将它放在你的~/.zsh/_git. 然后把它放在你的 fpath 上:
fpath=(~/.zsh $fpath)
You should be flying now.
你现在应该飞了。
As another comment here explains; another option is to use oh-my-shand enable the gitfastplugin, which achieves the same thing.
正如这里的另一条评论所解释的那样;另一种选择是使用oh-my-sh并启用gitfast插件,这可以实现相同的目的。
Why would Zsh developers insist on making their code slow? I don't know, but here you can see a sample of their reasoning: Re: Slowness issue with git completion.
为什么 Zsh 开发人员坚持让他们的代码变慢?我不知道,但在这里您可以看到他们推理的示例:Re: Slowness issue with git completion。
回答by caveman
One very quick and dirty solution is to delete the following file responsible for the auto-completion.
一种非常快速和肮脏的解决方案是删除以下负责自动完成的文件。
/usr/local/git/contrib/completion/git-completion.bash
回答by MarcH
According to the answer to git bash auto complete slow on windows 7 x64, git 2.13 comes with a faster git-completion.bash
根据git bash auto complete slow on windows 7 x64的答案,git 2.13 提供了更快的git-completion.bash

