Skip to content

Instantly share code, notes, and snippets.

@cie
Created January 24, 2014 19:27
Show Gist options
  • Save cie/8604271 to your computer and use it in GitHub Desktop.
Save cie/8604271 to your computer and use it in GitHub Desktop.
A colored indicator of the git tree status
git_ps1() {
GIT_PS1="$(__git_ps1)"
if [ "$GIT_PS1" ]; then
GIT_STATUS=$(git status --porcelain)
# if there are modified files
if echo "$GIT_PS1" | grep 'CONFLICT' > /dev/null; then
GIT_COLOR=31
elif echo "$GIT_STATUS" | grep '^.M' > /dev/null ; then
GIT_COLOR=35
# if there are unknown files
elif echo "$GIT_STATUS" | grep '^??' > /dev/null ; then
GIT_COLOR=33
# if there are staged changes
elif echo "$GIT_STATUS" | grep '^[^ ]' > /dev/null ; then
GIT_COLOR=36
else
GIT_COLOR=32
fi
echo -ne '\033[01;'$GIT_COLOR'm'"$GIT_PS1"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment