Colorised Build Success Message

My current project has a neat trick we picked up where the build has a red or green banner at the end when you run it locally to give good feedback about the build status. I’m not sure who originated it, but thanks!

I just had to tweak it a bit to get it working on OS X so I thought I would document the trick here. - OS X

CMD=”./tools/ant/bin/ant -lib ./asl/lib/jdepend $@”
echo “Running command [${CMD}] …”
if [ “$?” -ne 0 ]; then
    echo -e “`tput setab 1`  `cat ./ci/failed.txt` `tput setab 0`”
    exit 1
    echo -e “`tput setab 2`  `cat ./ci/passed.txt`  `tput setab 0`”
    exit 0

This assumes you have two supporting files ./ci/passed.txt and ./ci/failed.txt which contain the message. You can generate messages to your taste here.

I have provided the files in this example here :



It has also been run under Ubuntu where the following works (it didnt work on OS X which is why I adapted it), but the tput should also work on Ubuntu. I’ve not explicitly tested this one!

if [ “$?” -ne 0 ]; then
    echo -e “\E[30;41m”
    cat ./ci/failed.txt
    echo -e “\E[0m”
    exit 1
    echo -e “\E[30;42m”
    cat ./ci/passed.txt
    echo -e “\E[0m”
    exit 0

Under windows you can actually make the entire screen of the terminal change color:

run.bat - WINDOWS

CALL tools\ant\bin\ant %*
color 4F
color 2F
color 07

iTerm – Upgrade your Terminal

Spending a lot of time in various ssh sessions?

A bit tired of trying to remember which tab is on which server with the default os x terminal ?

So was I. Hunting around, I saw various hacks (e.g. a bash script, or applescript) to achieve this but also an app called iTerm.

Its free and within 30mins I was pretty much back to my previous terminal existence but with the names of my servers and my username in the tabs titles.


Some things I learned:

1) Some of the preferences I had to hunt for:

Not everything is available from iTerm–>Preferences. There are a couple of menu options of interest (this is iTerm 0.9.6).

View–>Show Session Info …

This lets you change the colors and fonts, etc for your terminal window and also update the default.

Bookmarks –> Manage Profiles …

This is where you can set a lot more options about your session, including making the cursor blink (Something for some reason I found essential:)

The reason they are here is because they are associated with bookmarks, a powerful feature that for example allows you to bookmark an ssh session, and have a whole set of preferences associated with that session.

I would like to see them all aggregated under the “Preferences” option though, because as a os x user, thats where I expect to find everything that I can configure (Posted as an feature request.

2) I wanted the title to change whenever I change directory. Simple, just need the following in my ~/.bash_profile (see here for differences between ~/.bashrc:

export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}: ${PWD/#$HOME/~}\007"'

3) This one is not probably very “good form”, but I really like the icon for the os x terminal window. So simply “Show Package Contents” on the and swap out /Contents/Resources/iTerm.icns with the equivalent in the Terminal application Terminal.icns

4) I also wanted a “close x” icon on each tab, and discovered that this is under Preferences –> Tab –> Use compact tab labels. You want to UN check this.

I now have exactly the same user experience as before with some great bonuses, for example, a cool feature is the “blur” of the transparency behind the window.


Sweet Search And Highlight Command

Been doing quite a bit of manipulating LaTeX files on the command line recently, and have a very sweet little command for searching for text in multiple files:

grep -r Hoffman */*.tex | less +/Hoffman

Where “Hoffman” is the search term which can of course be any regular expression.

The “less” command has a very convenient argument “+” which allows you to pass a search term in and will automatically highlight it for you.

The -r in grep recurses directories and */*.tex looks for all tex files. the | pipes the result to less.