Building simplicidade.org: notes, projects, and occasional rants

Script to deal with multiple VCSs

I work at 8 different projects now (5 consulting, 3 personal business), and between them, I use 4 different version control systems: cvs, svn, git and darcs.

To keep myself sane, I developed a set of front-end scripts to deal with the most common operations: diff, commit, add files, and update.

Starting today and during the next week I'll post all of those scripts online, and eventually I'll also repackage them in a repository that people can pull from if interested. All the scripts are licensed in the Artistic License, and the usual disclaimer applies: they work for me, if they burn down your computer or any surrounding environment (like your house, for example), you get to deal with the fire department yourself.

The base of all the other scripts is the x-vcs-discover that basically will tell you which of those systems the current directory is in.

The script takes no parameters, and will output to the stdout a single line with the VCS that was detected.

#!/bin/sh
#

Discover the VCS that is being used in the current dir if any

#

© Pedro Melo, 2007 - Artistic License, same as Perl

#

vcs= found=

while [ -z "$found" -a -z "$vcs" ] ; do cwd=pwd if [ "$cwd" == "/" -o "$cwd" == "$HOME" ] ; then found='give up' elif [ -d CVS ] ; then vcs=cvs elif [ -d .svn ] ; then vcs=svn elif [ -d .git ] ; then vcs=git elif [ -d "_darcs" ] ; then vcs=darcs else cd .. fi done

if [ -n "$vcs" ] ; then echo $vcs fi