How To : Adding SVN Info To Your Prompt
Ever since I switched to Linux years and years ago (and since then, to OS X), I’ve been carrying around a .profile script to configure my shell environment. The other day, I was browsing Ars Technica when I found a poster who had a very nice script in his prompt to add GIT info to his PS1 variable. Since I mostly use Subversion, I knew I had to adapt it but someone already did all the work! Let’s recap. My prompt usually looks like this:
user@computer ~/Documents/LCMM/Site/lcmm/trunk
That’s pretty good, but what if you could have SVN info when in a local repository. Here’s what I’ve got now:
user@computer ~/Documents/LCMM/Site/lcmm/trunk
SVN => [trunk:92]$
This gives me not only the local path, but also the current SVN path and the revision of the current directory. Of course, once you’re got that you can imagine other improvements that could be done here. To do that, here’s what I did. First, I downloaded this script on GitHub and placed it in /usr/local/bin (put it anywhere you want, it doesn’t matter).
Next, edit your bash init script (.profile for example) and add:
source /usr/local/bin/__svn_ps1.sh
export PS1="\u@\h \w \`__svn_ps1\`\$ "
That’s it. Pretty neat trick that could be adapted to anything else really. It works because the function returns either SVN info or nothing at all if this is not a local SVN repository.