-
-
Save TylerJWhit/63c084d0b7fe9327804da27052e22d36 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
# Original Source https://gist.github.com/chrisnolet/46206e21d59f8250bb979a8516a9a034 | |
# Modified to stick with Pop_OS! Style. | |
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 | |
} | |
#New PS1: | |
export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$(markup_git_branch \$(parse_git_branch))\$ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original source: https://gist.github.com/henrik/31631
Derivative with --porcelain and color escaping: https://gist.github.com/chrisnolet/46206e21d59f8250bb979a8516a9a034
This fork allows uniformity with default Pop_OS! gnome terminal PS1 settings, and reintegrates the header change behavior.