Skip to content

Instantly share code, notes, and snippets.

@shreyansb
Created August 18, 2011 14:50
Show Gist options
  • Save shreyansb/1154210 to your computer and use it in GitHub Desktop.
Save shreyansb/1154210 to your computer and use it in GitHub Desktop.
git branch and cleanliness status in the bash prompt
parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
parse_git_branch() {
git branch 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/(\1$(parse_git_dirty))/"
}
PROMPT_COMMAND='CurDir=`pwd|sed -e "s!$HOME!~!"|sed -E "s!([^/])[^/]+/!\1/!g"`'
PS1='[\u@\h $CurDir $(parse_git_branch)]\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment