Mike Hommey explains how to get VCS information in his bash prompt. Cool idea but not quite the way I like it, so I did a few more iterations...

The main problem is that it doesn't play nice with symlinks. I often find myself making a large checkout of a the full project and then have symlinks to the parts I'm working with.

Minor details is that I don't like having a bold font in my prompt, I don't care about the URI-part of the prompt, and I'm only using Subversion. So my quick 5 minutes hack: (See Mike's blog for the explanations)


# Fancy svn enabled PROMPT
__vcs_dir() {
  local vcs base_dir sub_dir ref get_dir

  get_dir() {
      ( cd $1
        echo ${PWD} )
  }

  sub_dir() {
    local sub_dir
    sub_dir=${PWD}
    sub_dir=${sub_dir#$1}
    echo ${sub_dir#/}
  }

  svn_dir() {
    [ -d ".svn" ] || return 1
    base_dir=$PWD
    while [ -d "$(get_dir $base_dir/..)/.svn" ]; do base_dir=$(get_dir "$base_dir/../"); done
    sub_dir=$(sub_dir "${base_dir}")
    ref=$(svn info "$(readlink -f $base_dir)" | awk '/^Revision/ { sub("[^0-9]*","",$0); print "rev:"$0 }')
    vcs="svn"
  }

  svn_dir ||
  base_dir="$PWD"

  echo "${base_dir/$HOME/~}${vcs:+[$ref]}${sub_dir}"
}

PS1='\u@\h:$(__vcs_dir)\$ '