mac 下git命令自动补全

一 、安装bash-completion

bash-completion 如果按照过了,请跳过步骤

<code class="hljs applescript has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">$ brew install bash-completion

<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">### 安装完成以后 查看</span>

$ brew info bash-completion
<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">### 会输出类似以下内容</span>
==> Caveats
Add <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">the</span> following lines <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span> your ~/.bash_profile:
  <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> [ -f $(brew <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">--prefix)/etc/bash_completion ]; then</span>
    . $(brew <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">--prefix)/etc/bash_completion</span>
  fi

Homebrew's own bash completion <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">script</span> has been installed <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">to</span>
  /usr/<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">local</span>/etc/bash_completion.d</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li></ul>

将if…then…那一句添加到~/.bash_profile(如果没有该文件,新建一个)

重启终端,以上为安装bash-completion部分。

二、拷贝文件、设置路径

访问下面网站

https://github.com/git/git.git

找到”contrib/completion/”目录下的git-completion.bash ,然后点击编辑,拷贝其内容,复制到文本文件,保存为 git-completion.bash 文件 
然后将文件用命令拷贝到 ~/ 目录下

<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">$ <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">cp</span> xxx/git-completion<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.bash</span> ~/<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.git</span>-completion<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.bash</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

xxx 为文件所在目录,注意拷贝后的文件名称为 .git-completion.bash

在~/.bashrc文件(该目录下如果没有,新建一个)中添加下边的内容

<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">$ source ~/<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.git</span>-completion<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.bash</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>
三、 启动: 终端输入
<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;">$ source ~/<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.git</span>-completion<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.bash</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>

不输入的话,不会起作用

将下面这句话 添加到~/.bash_profile 

<code class="hljs bash has-numbering" style="display: block; padding: 0px; background-color: transparent; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background-position: initial initial; background-repeat: initial initial;"><span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">if</span> [ <span class="hljs-operator" style="box-sizing: border-box;">-f</span> ~/.git-completion.bash ]; <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">then</span>
   . ~/.git-completion.bash
<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">fi</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; background-color: rgb(238, 238, 238); top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right;"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

不添加想要补全起作用,每次都需要执行  
source ~/.git-completion.bash 
补全才能生效


原文:http://blog.csdn.net/chenbifeng/article/details/51570606


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值