Skip to content

Instantly share code, notes, and snippets.

@rmunn
Created March 9, 2016 03:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmunn/2d96c182671040fa2192 to your computer and use it in GitHub Desktop.
Save rmunn/2d96c182671040fa2192 to your computer and use it in GitHub Desktop.
How to get a nice Bash prompt that includes your current Git branch

Edit your .bashrc as follows. Before the "case $TERM" statement that sets color_prompt, add the following:

# GNOME Terminal is broken re: $TERM settings
if [ "$COLORTERM" = "gnome-terminal" -a "$TERM" = "xterm" ]; then
    TERM="xterm-256color"
fi

Now edit that "case $TERM" statement to look like this:

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|xterm-256color) color_prompt=yes;;
    *-256color) color_prompt=yes;;
esac

Finally, look for the part of your .bashrc that sets the PS1 variable and make it look something like this:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[01;31m\]$(__git_ps1)\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1)\$ '
fi
unset color_prompt force_color_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment