1.安裝HomeBrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. 安裝bash-completion
brew install bash-completion
$ brew info bash-completion
bash-completion: stable 1.3 (bottled)
Programmable completion for Bash 3.2
https://bash-completion.alioth.debian.org/
Conflicts with:
bash-completion@2 (because Differing version of same formula)
/usr/local/Cellar/bash-completion/1.3_3 (189 files, 608.6KB) *
Poured from bottle on 2018-04-06 at 15:50:57
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/bash-completion.rb
==> Caveats
Add the following line to your ~/.bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
將[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
添加到~/.bash_profile
(沒有就創建一個)
$ cat .bash_profile
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
3. 下載Docker和Git的completion文件
$ docker version
Client:
Version: 18.03.0-ce
API version: 1.37
Go version: go1.9.4
Git commit: 0520e24
Built: Wed Mar 21 23:06:22 2018
OS/Arch: darwin/amd64
Experimental: false
Orchestrator: swarm
......
從這裡docker/docker-ce(如果你的docker版本不是上面顯示的那樣,那麼需要重新選擇對應的分支)複製文件內容,然後將內容添加到/usr/local/etc/bash_completion.d/docker
。當然能用curl
工具更好了。
從這裡git/git複製文件內容添加至/usr/local/etc/bash_completion.d/git
。
最後重啟終端。