自制的git不使用补全 [英] Homebrew’s `git` not using completion

查看:103
本文介绍了自制的git不使用补全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用OSX的git时,修改文件后,我可以简单地执行git commit <tab>,这会将文件名自动完成为已修改的文件名.但是,如果我从自制软件安装了较新版本的git并使用了该功能,则该功能将不再起作用(这意味着我按<tab>,它只是询问"我要对其执行处理的文件,甚至包括那些保持不变).

When using OSX’s git, after I modify a file I can simply do git commit <tab>, and that’ll auto complete the file’s name to the one that was modified. However, if I install a newer version of git from homebrew and I use it, that feature no longer works (meaning I press <tab> and it just "asks" me what file I want to do it on, even including the ones that have no changes).

任何人都可以阐明为什么以及如何解决该问题吗?我更喜欢使用自制的git,因为它是最新的.

Can anyone shed some light as to why, and how to solve that? I’d prefer using homebrew’s git, since it’s more up-to-date.

我的外壳是zsh,并且安装bash-completionzsh-completions均无效(即使遵循自制软件的安装后说明).

My shell is zsh, and Neither installing bash-completion or zsh-completions worked (even after following homebrew’s post-install instructions).

另外,在用自制软件安装git后,会说

Also, after installing git with homebrew it says

Bash completion has been installed to: /usr/local/etc/bash_completion.d
zsh completion has been installed to: /usr/local/share/zsh/site-functions

所以我不能使用其中之一吗?

So shouldn’t I be able to use one of those?

推荐答案

您在寻找:

brew install git bash-completion

如warpc的评论所述,您需要在~/.bash_profile中添加以下内容,以使自制软件的bash补全功能正常工作:

As warpc's comment states, you'll need to add the following to your ~/.bash_profile to get homebrew's bash-completion working:

if [ -f $(brew --prefix)/etc/bash_completion ]; then
    . $(brew --prefix)/etc/bash_completion
fi

在安装bash-completion公式时,在警告中提到了以上内容.

The above is mentioned in the caveats when you install the bash-completion formula.

注意:如果您使用的是Bash v4或更高版本(通过brew install bash),则要使用brew install bash-completion@2,要启用制表符补全功能,请将以下内容添加到~/.bash_profile如警告所述:

Note: if you are using Bash v4 or later (via brew install bash) then you're going to want to use brew install bash-completion@2, to enable tab completion add the following to ~/.bash_profile as described in the caveats:

export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"

对于git,docker,youtube-dl和其他可能包含在$(brew --prefix)/etc/bash_completion.d/目录中的补全,额外的导出是必需的.

The additional export is necessary for git, docker, youtube-dl, and other completions which may be included in the $(brew --prefix)/etc/bash_completion.d/ directory.

这篇关于自制的git不使用补全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆