Mac 配置git自动提示和命令行分支高亮

使用zsh的稍后,在命令行里面会提示当期那的分支名称。那么使用原始的terminal的时候,应该如何配置呢?

shell自动补全和自动提示配置

参考http://blog.csdn.net/mycwq/article/details/52420330

git 自动补全和自动提示

  • 在用户目录下~执行如下命令
curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
  • 然后在 .bash_profile中增加git 自动补全和自动提示配置
# add git-completion.bash
source ~/git-completion.bash
  • 使配置生效
source ~/.bash_profile

shell命令行提示配置PS1

颜色和语法配置参考 http://rsljdkt.iteye.com/blog/1141561

增加git的高亮配置

.bashrc中增加对PS1变量的配置

## PS1 命令行提示修改
function git-branch-name {
   git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3
 }
 function git-branch-prompt {
   local branch=`git-branch-name`
   if [ $branch ]; then printf " (%s)" $branch; fi
 }
 export PS1='\u:\[\e[36;47.0m\]\W\[\e[0m\]\[\e[35;47.1m\]$(git-branch-prompt)\[\e[0m\]\$ '
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容