(1)检查是否安装brew,没有安装的请输入以下命令(Homebrew官网地址:https://brew.sh/index_zh-cn)
brew list
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
(2)通过brew 安装bash-completion
brew install bash-completion
(3)查看bash-completion 是否安装成功
brew list
(4)查看bash-completion 文件信息
brew info bash-comletion
(5)根据第四步输出内容的提示,把对应的命令行加入~/.bash_profile 文件中
## 这里需要注意,版本不一样,加入的东西不一样,具体需要看输出内容的提示
## [ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion,这是我操作时输出的内容提示
(6)确认自己电脑已经装git,并确定安装的版本
brew install git
git --version
(7)下载git-completion.bash 文件,保存至/usr/local 目录
## git-completion.bash 可以在GitHub 下载,因为这个文件是存放在git 源码中的,但是需要注意和本地安装的git 版本一致
## https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
curl -L -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
(8)把git-completion.bash 文件复制到用户目录,并命名为.git-completion.bash
cp /usr/local/git-completion.bash ~/.git-completion.bash
(9)配置~/.bash_profile 文件
source ~/.git-completion.bash
(10)保存~/.bash_profile 文件,并执行source ~/.bash_profile 命令
## 注意,我们可以省略第八、九、十步,执行以下步骤
cd /usr/local/opt/bash-completion/etc/bash_completion.d
cp /usr/local/git-completion.bash .
brew unlink bash-completion
brew link bash-completion