Skip to content

Instantly share code, notes, and snippets.

@marek-panek
Created October 18, 2020 14:20
Show Gist options
  • Save marek-panek/914be7666b9e3df994c89e7f5dc9140c to your computer and use it in GitHub Desktop.
Save marek-panek/914be7666b9e3df994c89e7f5dc9140c to your computer and use it in GitHub Desktop.
Add current git branch name to bash prompt
1. Edit .bashrc file and and the following entries
parse_git_branch() {
git rev-parse --abbrev-ref HEAD 2> /dev/null | sed -e 's/^/(/' -e 's/$/) /'
}
if [ "$color_prompt" = yes ]; then
PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w \[\e[91m\]\$(parse_git_branch)\[\033[00m\]\$ "
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment