Mac git命令自動(dòng)補(bǔ)全

在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!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容