Skip to content

Instantly share code, notes, and snippets.

@akomakom
Forked from woods/git_svn_bash_prompt.sh
Last active September 19, 2018 18:15
Show Gist options
  • Select an option

  • Save akomakom/fcd3a57d9aed94a313a948f77a37469b to your computer and use it in GitHub Desktop.

Select an option

Save akomakom/fcd3a57d9aed94a313a948f77a37469b to your computer and use it in GitHub Desktop.
Set color bash prompt according to git/svn branch, and return status of last command.
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