Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save HungYuHei/1267963 to your computer and use it in GitHub Desktop.

Select an option

Save HungYuHei/1267963 to your computer and use it in GitHub Desktop.
Display git branch in bash prompt with color
D=$'\e[37;40m'
PINK=$'\e[35;40m'
GREEN=$'\e[32;40m'
ORANGE=$'\e[33;40m'
WHITE=$'\e[33;0m'
YELLOW=$'\e[33;33m'
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
#export PS1="\n[\u@\h \w]${YELLOW}\$(git branch 2>/dev/null | grep '^*' | colrm 1 2)\n${WHITE}\$ "
export PS1='\n${PINK}\u ${D}@ ${GREEN}\h ${D}in ${ORANGE}\w ${D}$(parse_git_branch)\n${WHITE}$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment