1. Install homebrew
2. Install Git and bash-completion: brew install git bash-completion
(Note: If this install fails with a 404 error, and you already have git installed, just remove the git part of this brew install)
在我电脑上已经安装了git,现在只需要安装bash-completion即可,执行如下命令
uxiaolei@duxiaoleideMacBook-Pro:~$brew install bash-completion Updating Homebrew... ==> Auto-updated Homebrew! Updated 1 tap (bazelbuild/tap). ==> Updated Formulae bazelbuild/tap/bazel ==> Downloading https://homebrew.bintray.com/bottles/bash-completion-1.3_3.high_sierra.bottle.tar.gz ######################################################################## 100.0% ==> Pouring bash-completion-1.3_3.high_sierra.bottle.tar.gz ==> Caveats Add the following line to your ~/.bash_profile: [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh" Bash completion has been installed to: /usr/local/etc/bash_completion.d ==> Summary 🍺 /usr/local/Cellar/bash-completion/1.3_3: 189 files, 608.2KB
查看bash-completion安装信息
duxiaolei@duxiaoleideMacBook-Pro:~$brew info bash-completion bash-completion: stable 1.3 (bottled) Programmable completion for Bash 3.2 https://salsa.debian.org/debian/bash-completion Conflicts with: bash-completion@2 (because Differing version of same formula) /usr/local/Cellar/bash-completion/1.3_3 (189 files, 608.2KB) * Poured from bottle on 2020-03-08 at 14:34:43 From: https://mirrors.ustc.edu.cn/homebrew-core.git/Formula/bash-completion.rb ==> Caveats Add the following line to your ~/.bash_profile: [[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh" Bash completion has been installed to: /usr/local/etc/bash_completion.d ==> Analytics install: 13,177 (30 days), 38,962 (90 days), 174,605 (365 days) install_on_request: 12,152 (30 days), 36,129 (90 days), 160,356 (365 days) build_error: 0 (30 days)
4. 主要看bash-completion安装信息中Caveats下面的提示,将如下内容添加到~/.bash_profile中,执行如下命令:
duxiaolei@duxiaoleideMacBook-Pro:~$echo "[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . \"/usr/local/etc/profile.d/bash_completion.sh\"" >> ~/.bash_profile duxiaolei@duxiaoleideMacBook-Pro:~$tail -n 1 .bash_profile [[ -r /usr/local/etc/profile.d/bash_completion.sh ]] && . "/usr/local/etc/profile.d/bash_completion.sh" duxiaolei@duxiaoleideMacBook-Pro:~$source .bash_profile
5. 在source完bash_profile 加载完环境变量后,切换到git 目录下执行git 命令可以看到,git 已经支持自动补全
uxiaolei@duxiaoleideMacBook-Pro:ogl-runtime$git che checkout cherry cherry-pick duxiaolei@duxiaoleideMacBook-Pro:ogl-runtime$git checkout