Ubuntu14.04 64位上配置终端显示git分支名称

    之前在Ubuntu14.04上在终端上显示git分支名称基本上都使用oh-my-zsh,可以参考 https://blog.csdn.net/fengbingchun/article/details/77803322  ,由于限制了权限,使得不能安装oh-my-zsh,显示错误如下:


        在 https://github.com/robbyrussell/oh-my-zsh/issues/4789 中给出了对上述错误的解释。

        不能使用oh-my-zsh,在网上 https://www.jianshu.com/p/82783f76a868 中介绍了一种方法,即在~/.bashrc文件末尾加入下面一段脚本并保存:  

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
}
PS1="\u@\h \[\033[0;36m\]\W\[\033[0m\]\[\033[0;32m\]\$(git-branch-prompt)\[\033[0m\] \$ "

        使修改生效,执行: $ source ~/.bashrc

        在有git的工作目录下,即会显示git分支名称,如下:


猜你喜欢

转载自blog.csdn.net/fengbingchun/article/details/80598509