Skip to content

Instantly share code, notes, and snippets.

@davidcotter
Created May 24, 2009 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidcotter/117129 to your computer and use it in GitHub Desktop.
Save davidcotter/117129 to your computer and use it in GitHub Desktop.
Git branch in bash prompt
# Git branch in bash prompt
# At the top of .bashrc
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
function prompt_with_git_branch {
case $TERM in
xterm*)
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
;;
*)
TITLEBAR=""
;;
esac
PS1="${TITLEBAR}\
\u@\h:\w\$(parse_git_branch)\$ "
PS2='> '
PS4='+ '
}
# At the bottom of .bashrc (so ot supercedes any other prompt stuff)
prompt_with_git_branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment