在Mac上安裝了git之后,發(fā)現(xiàn)命令不能自動(dòng)補(bǔ)全,本文介紹怎么讓git命令能夠自動(dòng)補(bǔ)全。
確保bash能夠自動(dòng)
在終端(本文使用的是OS X的終端)執(zhí)行如下命令:
ccli@ccli-mac:dal$ brew list
看看是否已經(jīng)安裝有bash-completion,比如我的機(jī)器(已經(jīng)安裝了)運(yùn)行上面的命令會(huì)顯示:
bash-completion glib libtiff perl sqlite
如果沒有安裝,運(yùn)行如下命令安裝bash-completion:
brew install bash-completion
等待安裝完成之后,運(yùn)行如下命令:
brew info bash-completion
運(yùn)行上面的命令后會(huì)在終端顯示下圖:?
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 (190 files, 676.4KB) *
? Poured from bottle on 2018-05-28 at 09:59:40
From: https://github.com/Homebrew/homebrew-core/blob/master/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: 14,875 (30 days), 44,147 (90 days), 189,622 (365 days)install_on_request: 13,491 (30 days), 40,092 (90 days), 173,591 (365 days)build_error: 0 (30 days)
仔細(xì)閱讀箭頭所指的地方,依照提示將這行內(nèi)容
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
添加到 ~/.bash_profile文件(如果沒有該文件,新建),然后重啟終端,bash-completion功能安裝完成。
讓git支持自動(dòng)補(bǔ)全
從github上clone git的源碼到本地:
git clone https://github.com/git/git.git
找到”contrib/completion/”目錄下的git-completion.bash,將該文件拷貝到~/目錄下下并重命名為.git-completion.bash:
cp git-completion.bash ~/.git-completion.bash
在~/.profile文件中追加如下內(nèi)容:
source ~/.git-completion.bash
重啟終端,現(xiàn)在git能夠使用tab鍵自動(dòng)補(bǔ)全命令了,enjoy it!