Skip to content

Instantly share code, notes, and snippets.

@hasselmm
Created April 22, 2009 18:31
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 hasselmm/99963 to your computer and use it in GitHub Desktop.
Save hasselmm/99963 to your computer and use it in GitHub Desktop.
# set variable identifying the git branch you work in (used in the prompt below)
bashrc_update_prompt() {
git_branch=$(
while [ "$PWD" != "/" ]; do
if [ -d ".git/objects" ]; then
git-branch 2>/dev/null | sed -ne 's/^\* //p'
break
fi
cd ..
done
)
}
PROMPT_COMMAND=bashrc_update_prompt
...
if [ "$color_prompt" = yes ]; then
PS1='\[\033[01;${ps1_color}m\]\u@\h\[\033[00m\]${debian_chroot:+($debian_chroot)}:\[\033[01;34m\]\w${git_branch:+\[\033[01;31m\](${git_branch})}\[\033[00m\]\$ '
else
PS1='\u@\h${debian_chroot:+($debian_chroot)}:\w${git_branch:+(${git_branch})}\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;\u@\h${debian_chroot:+($debian_chroot)}: \w${git_branch:+(${git_branch})}\a\]$PS1"
;;
*)
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment