Homebrew 的 `git` 不使用补全 [英] Homebrew’s `git` not using completion
问题描述
当使用 OSX 的 git 时,在我修改文件后,我可以简单地执行 git commit
,这会自动将文件名补全为修改后的文件名.但是,如果我从自制软件安装更新版本的 git 并使用它,该功能将不再有效(意味着我按
并且它只是询问"我想要做什么文件它打开,甚至包括那些没有变化的).
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).
谁能解释一下为什么,以及如何解决这个问题?我更喜欢使用 homebrew 的 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.
我的 shell 是 zsh,并且安装 bash-completion
或 zsh-completion
都不起作用(即使按照 Homebrew 的安装后说明进行操作).
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
中,以使 homebrew 的 bash-completion 工作:
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
,要启用 tab 补全,将以下内容添加到 ~/.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.
这篇关于Homebrew 的 `git` 不使用补全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!