當我第一次使用mac電腦的時候,由於我是從事軟件開發的程序員,所以必須經常要使用到git,然而發現在mac系統下,git不能實現命令的自動補全,然后網上查找資料,找到了解決辦法,終於可以實現了git命令的自動補全功能,現在分享如下。
需要購買阿里雲產品和服務的,點擊此鏈接領取優惠券紅包,優惠購買哦,領取后一個月內有效: https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=fp9ccf07
安裝Homebrew
首先安裝配置Homebrew(注:如果已經安裝過就跳過):
HomeBrew的網址:https://brew.sh/index_zh-cn.html
在終端輸入如下命令:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
然后就會開始安裝,中間會提示輸入系統用戶的密碼,安裝成功后會有如下提示:
此時可以在命令行中輸入命令brew進行測試,可以看到如下結果,說明安裝成功。
正式開始
一 、安裝bash-completion
bash-completion 如果按照過了,請跳過步驟
$ brew install bash-completion ### 安裝完成以后 查看 $ brew info bash-completion ### 會輸出類似以下內容 ==> Caveats Add the following lines to your ~/.bash_profile: if [ -f $(brew --prefix)/etc/bash_completion ]; then . $(brew --prefix)/etc/bash_completion fi Homebrew's own bash completion script has been installed to /usr/local/etc/bash_completion.d
將if…then…那一句添加到~/.bash_profile(如果沒有該文件,新建一個)
重啟終端,以上為安裝bash-completion部分。
二、拷貝文件、設置路徑
訪問下面網站
https://github.com/git/git.git
找到”contrib/completion/”目錄下的git-completion.bash ,然后點擊編輯,拷貝其內容,復制到文本文件,保存為 git-completion.bash 文件
然后將文件用命令拷貝到 ~/ 目錄下
$ cp xxx/git-completion.bash ~/.git-completion.bash
xxx 為文件所在目錄,注意拷貝后的文件名稱為 .git-completion.bash
在~/.bashrc文件(該目錄下如果沒有,新建一個)中添加下邊的內容:
source ~/.git-completion.bash
三、 啟動: 終端輸入
$ source ~/.git-completion.bas
注:不輸入的話,不會起作用
將下面這句話 添加到~/.bash_profile
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
不添加想要補全起作用,每次都需要執行
source ~/.git-completion.bash
補全才能生效
注:原文地址:http://blog.csdn.net/chenbifeng/article/details/51570606