Ubuntu 终端下显示git分支的状态 并保持颜色

 将以下内容添加到 ~/.bashrc

function parse_git_dirty {

  [[ $(git status 2> /dev/null | tail -n1) != "无文件要提交,干净的工作区" ]] && echo "*"
}
function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\e[1;36m\]$(parse_git_branch)\[\e[0m\]$ '

你可能感兴趣的:(Ubuntu 终端下显示git分支的状态 并保持颜色)