Skip to content

Instantly share code, notes, and snippets.

@trevmex
Created July 6, 2011 23:21
Show Gist options
  • Save trevmex/1068583 to your computer and use it in GitHub Desktop.
Save trevmex/1068583 to your computer and use it in GitHub Desktop.
Adding git and svn info to the 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_repo {
info=$(svn info 2> /dev/null) || return
root=$(echo $info | sed -e 's/^.*Repository Root: //g' -e 's,.*/,,g' -e 's/ .*//g')
revision=$(echo $info | sed -e 's/^.*Revision: //g' -e 's/ .*//g')
echo " ($root:$revision)"
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NORMAL="\[\033[0m\]"
export PS1="$RED\u@\h:$GREEN\W$YELLOW\$(parse_git_branch)\$(parse_svn_repo)$NORMAL\$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment