Skip to content

Instantly share code, notes, and snippets.

@filipsalomonsson
Created December 3, 2008 20:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save filipsalomonsson/31675 to your computer and use it in GitHub Desktop.
Save filipsalomonsson/31675 to your computer and use it in GitHub Desktop.
function parse_git_branch {
git_status="$(git status 2> /dev/null)"
pattern="^# On branch ([^${IFS}]*)"
if [[ ! ${git_status}} =~ "working directory clean" ]]; then
state="*"
fi
# add an else if or two here if you want to get more specific
if [[ ${git_status} =~ ${pattern} ]]; then
branch=${BASH_REMATCH[1]}
echo "[${branch}${state}]"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment