A trivial bash script

October 4th, 2008

Nick Rutherford

Over the summer I was working with another company doing some build system work, which involved a lot of shell scripting (it was more to do with integration than make).

I’ve not got to the stage where I use Ruby on a daily basis for everything yet, which is where I used to be with Java (which was horrible for it!). Currently the weapon of choice is bash scripting, alas, I don’t have my handy O’Reilly book to reference anymore and I’m starting to forget things. Man pages and Google go a long way, but the reason I got the book in the first place was to save time!

Anyway, here’s what I’m using to update all my textmate bundles, which are a mixture of svn and git repos. Usual disclaimer: Y.M.M.V., don’t use it to baby-sit your kids while they play in traffic, etc. An obvious flaw with it is if git or svn fails you won’t get any feedback about it, and if the svn message changes it’ll stop working!


#!/bin/bash
cd ~/Library/Application\ Support/TextMate/Bundles/

export LC_CTYPE=en_GB.UTF-8

for f in ./*; do 
    cd "$f" #enter bundle dir
    echo "Updating $f" 
    git pull &> /dev/null \
        || svnres=$(svn update) \
        && [[ $svnres  = "Skipped '.'" ]] \
        && echo "*** Failed to update $f (is it a local setting not a repo?)" 
    cd .. #return to bundles dir
done

Feel free to comment / improve / re-implement in Ruby.

Sorry, comments are closed for this article.