MacOS 安装 Bash-Completion 命令自动补全功能

安装 brew

Install Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

安装 bash 自动补全包

Install bash-completion

brew install bash-completion
ECMBP:~ e.c.$ brew install bash-completion
==> Downloading https://homebrew.bintray.com/bottles/bash-completion-1.3_3.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring bash-completion-1.3_3.mojave.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, 607.8KB

配置环境

Configuration setting

cat >> ~/.bash_profile <<EOL

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

EOL
source ~/.bash_profile

添加 Docker 命令补全功能

Add docker bash completion

cd /usr/local/etc/bash_completion.d
ln -s /Applications/Docker.app/Contents/Resources/etc/docker.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-machine.bash-completion
ln -s /Applications/Docker.app/Contents/Resources/etc/docker-compose.bash-completion

关闭当前终端重开终端(restart the terminal)

ECMBP:~ e.c.$ docker [TAB][TAB]
attach     diff       images     logout     ps         run        stats      unpause
build      events     import     logs       pull       save       stop       update
commit     exec       info       network    push       search     swarm      version
config     export     inspect    node       rename     secret     system     volume
container  help       kill       pause      restart    service    tag        wait
cp         history    load       plugin     rm         stack      top        
create     image      login      port       rmi        start      trust