Last active
December 25, 2015 16:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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