Skip to content

Instantly share code, notes, and snippets.

@jeffcarp
Last active December 23, 2015 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffcarp/6618224 to your computer and use it in GitHub Desktop.
Save jeffcarp/6618224 to your computer and use it in GitHub Desktop.
Color your git branch green or red based on whether you have uncommitted changes. (Put it in your ~/.bash_profile)
XRED="\033[0;31m"
XGREEN="\033[0;32m"
XNO_COLOUR="\033[0m"
function parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
branch_colorize () {
if [ -d .git ]
then
if ! git diff-files --quiet --ignore-submodules --
then
echo -e "$XRED$(parse_git_branch)$XNO_COLOUR"
else
echo -e "$XGREEN$(parse_git_branch)$XNO_COLOUR"
fi
fi
}
PS1="夢 \w\$(branch_colorize) \$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment