Skip to content

Instantly share code, notes, and snippets.

@TylerJWhit
Forked from chrisnolet/.bash_profile
Last active March 12, 2020 02:14
Show Gist options
  • Save TylerJWhit/63c084d0b7fe9327804da27052e22d36 to your computer and use it in GitHub Desktop.
Save TylerJWhit/63c084d0b7fe9327804da27052e22d36 to your computer and use it in GitHub Desktop.
Color-coded git branch for bash prompt
# 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))\$ "
@TylerJWhit
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment