Skip to content

Instantly share code, notes, and snippets.

@TylerJWhit
Forked from chrisnolet/.bash_profile
Created March 1, 2020 07:57
Show Gist options
  • Save TylerJWhit/10f3969be607bf1bfa7cd9f5f248cb67 to your computer and use it in GitHub Desktop.
Save TylerJWhit/10f3969be607bf1bfa7cd9f5f248cb67 to your computer and use it in GitHub Desktop.
Color-coded git branch for bash prompt
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* (*\([^)]*\))*/\1/'
}
markup_git_branch() {
if [[ -n $@ ]]; then
if [[ -z $(git status --porcelain 2> /dev/null) ]]; then
echo -e " \001\033[32m\002($@)\001\033[0m\002"
else
echo -e " \001\033[31m\002($@)\001\033[0m\002"
fi
fi
}
export PS1="\h:\W\$(markup_git_branch \$(parse_git_branch)) \u$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment