-
-
Save TylerJWhit/10f3969be607bf1bfa7cd9f5f248cb67 to your computer and use it in GitHub Desktop.
Color-coded git branch for bash prompt
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
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