Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@joemaller
Last active December 25, 2015 16:12
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 joemaller/4527475 to your computer and use it in GitHub Desktop.
Save joemaller/4527475 to your computer and use it in GitHub Desktop.
A bash function for coloring the current git branch. Red for dirty, yellow if all files are staged and clean is green. This uses the color functions from https://gist.github.com/4503986
# https://gist.github.com/joemaller/4527475
#
# A simple bash function for coloring the current git branch.
# - Red: Tree is dirty
# - Yellow: All modified files are staged
# - Green: Tree is clean
#
# This uses the color functions from https://gist.github.com/4503986
function git_branch() {
is_git=$(git status --porcelain 2> /dev/null ) || return
branch=$(git symbolic-ref --short HEAD 2> /dev/null)
if [ -z "$branch" ]; then
branch=$(git status | sed -n 1p )
fi
is_dirty=$(git update-index --refresh 2> /dev/null)
is_staged=$(git diff-index --cached HEAD 2> /dev/null)
if [ -n "$is_dirty" ]; then
echo $(DARK_RED "[$branch]")
elif [ -n "$is_staged" ]; then
echo $(DARK_YELLOW "[$branch]")
else
echo $(DARK_GREEN "[$branch]")
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment