When you include this in your ~/.bash_login
file:
# Show current git branch or SVN subfolder in prompt.
GREEN="\[\033[0;32m\]"
LIGHT_GREEN="\[\033[1;32m\]"
GRAY="\[\033[1;30m\]"
LIGHT_BLUE="\[\033[1;34m\]"
LIGHT_GRAY="\[\033[0;37m\]"
COLOR_OFF="\[\e[0m\]"
function prompt_func() {
branch_pattern="\* ([^$IFS]*)"
PS1="$LIGHT_GRAY`date +%H:%M:%S`$COLOR_OFF $LIGHT_GREEN\w$COLOR_OFF"
if [[ -d "./.git" && "$(git branch --no-color 2> /dev/null)" =~ $branch_pattern ]]; then
branch="${BASH_REMATCH[1]}"
PS1+=":$LIGHT_BLUE$branch$COLOR_OFF"
elif [[ -d "./.svn" ]]; then
path_pattern="URL: ([^$IFS]*).*Repository Root: ([^$IFS]*).*Revision: ([0-9]*)"
if [[ "$(svn info 2> /dev/null)" =~ ${path_pattern} ]]; then
branch=`/usr/bin/ruby -e 'print ARGV[0][ARGV[1].size + 1..-1] || "/"' ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}`
revision="${BASH_REMATCH[3]}"
PS1+=":$LIGHT_BLUE$branch$GRAY@$revision$COLOR_OFF"
fi
fi
PS1+=" "
}
PROMPT_COMMAND=prompt_func
…it should show you, depending on what kind of folder you’re in, the current git
or svn
branch:
~ cd ruby/coderay
~/ruby/coderay:trunk@644 cd ../coderay-0.9
~/ruby/coderay-0.9:branches/0.9@641 cd ~/studies/ikiwiki/
~/studies/ikiwiki:master
It is quite fast, but needs Ruby (any idea for a bash-only version?)
Update: Fixed a few things.
Update 2: Cleanup, SVN revison number.