1、确保已经安装brew
执行brew -v检查是否安装brew
2、安装bash-completion
执行 brew list检查已经安装的包是否有bash-completion,若无,则对其进行安装
brew install bash-completion
必须要确保brew list执行后,bash-completion在其中才能保证安装成功
3、修改~/.bash_profile文件
添加以下代码到这个文件里:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
4、添加Git补全支持
注意:如果到步骤三还不生效的话,再执行步骤4
印象中步骤4也只执行了前两行
cd /usr/local/opt/bash-completion/etc/bash_completion.d
curl -L -O http https://raw.github.com/git/git/master/contrib/completion/git-completion.bash
brew unlink bash-completion
brew link bash-completion
可能出现的问题
1、安装bash-completion时,一直显示Updating Homebrew...
方法1:直接关闭brew每次执行命令时的自动更新(推荐)
vim ~/.bash_profile
# 新增一行
export HOMEBREW_NO_AUTO_UPDATE=true
新增之后,输入:wq!保存并退出
方法2:替换brew源
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
#替换homebrew-core.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
brew update
2、有时候bash_profile文件的内容需要改为下面的代码
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
3、安装bash-completion时提示403
忘记如何解决的了