Apr 03

Even friendlier shell prompts for version control

Including version control status in your Bash prompt, now for SVN, CVS, Mercurial and Git

I've extended the earlier VCS-friendly shell prompt to add support for Mercurial and you can now get my current .bash_profile from GitHub:

__has_parent_dir(){# Utility function so we can test for things like .git/.hg without firing
 # up a separate process
 test -d "$1"&& return 0;

 current="."while [ !"$current" -ef "$current/.." ];doif [ -d "$current/$1" ];then
   return 0;fi
  current="$current/..";done

 return 1;}__vcs_name(){if [ -d .svn ];then 
 echo " [svn]";elif [ -d RCS ];then 
 echo " [RCS]";elif __has_parent_dir ".git";then
  echo "$(__git_ps1 ' [git %s]')";elif __has_parent_dir ".hg";then
  echo " [hg $(hg branch)]"fi}

PS1='\[\033]0;\u@\h:\w\007\]\u@\h:\w$(__vcs_name) $ '