Skip to content

Instantly share code, notes, and snippets.

@nealfennimore
Created May 6, 2017 22:33
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 nealfennimore/06bed71455b9e8e05c6ba735796afec1 to your computer and use it in GitHub Desktop.
Save nealfennimore/06bed71455b9e8e05c6ba735796afec1 to your computer and use it in GitHub Desktop.
Terminal git branch state
# https://gist.github.com/chrisnolet/d07a55580337cfe7d5388b1d3c4960cc
function git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (*\([^)]*\))*/\1/'
}
function markup_git_branch {
if [[ -n $@ ]]; then
if [[ -z $(git status --porcelain 2> /dev/null | tail -n1) ]]; then
echo -e " \001\033[32m\002($@)\001\033[0m\002"
else
echo -e " \001\033[31m\002($@)\001\033[0m\002"
fi
fi
}
PS1="\$(markup_git_branch \$(git_branch))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment