Skip to content

Instantly share code, notes, and snippets.

@atroutt
Created May 8, 2013 19:00
Show Gist options
  • Save atroutt/5542757 to your computer and use it in GitHub Desktop.
Save atroutt/5542757 to your computer and use it in GitHub Desktop.
Add your git branch name to your bash prompt and color the prompt. Put this in your bash.rc or whatever
# From http://trevmex.com/post/7320627392/how-to-add-git-and-subversion-info-to-a-bash-prompt
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo " ("${ref#refs/heads/}$(parse_git_dirty)")"
}
function parse_svn_repo2 {
info=$(svn info 2> /dev/null) || return
root=$(echo $info | sed -e 's/^.*URL: //g' -e 's,.*/,,g' -e 's/ .*//g')
revision=$(echo $info | sed -e 's/^.*Revision: //g' -e 's/ .*//g')
echo " ($root:$revision)"
}
RED="\[\033[0;34m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;36m\]"
NORMAL="\[\033[0m\]"
export PS1="$RED\u@\h:$GREEN\W$YELLOW\$(parse_git_branch)\$(parse_svn_repo2)$NORMAL\$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment