Skip to content

Instantly share code, notes, and snippets.

@nuc
Created September 21, 2011 09:47
Show Gist options
  • Save nuc/1231685 to your computer and use it in GitHub Desktop.
Save nuc/1231685 to your computer and use it in GitHub Desktop.
Colorized git status in bash prompt
RED=`echo -e '\033[01;31m'`
BLUE=`echo -e '\033[01;34m'`
GREEN=`echo -e '\033[01;32m'`
NORMAL=`echo -e '\033[00m'`
function is_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]]
}
function parse_git_branch {
if is_git_dirty
then
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/($RED\1*$NORMAL)/"
else
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/($GREEN\1$NORMAL)/"
fi
}
PS1="\w \$(parse_git_branch)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment