bash

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.

run.sh - OS X

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

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 :

passed.txt

failed.txt

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
else
    echo -e "\E[30;42m"
    cat ./ci/passed.txt
    echo -e "\E[0m"
    exit 0
fi

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

run.bat - WINDOWS

CALL tools\ant\bin\ant %*
IF ERRORLEVEL 1 GOTO RedBuild
IF ERRORLEVEL 0 GOTO GreenBuild
:RedBuild
color 4F
GOTO TheEnd
:GreenBuild
color 2F
:TheEnd
PAUSE
color 07
  • Share/Bookmark

bash
build
linux commands
os x

Comments (0)

Permalink

Check if an command was successful in bash

When scripting gigantic build scripts with bash, its important that if anything fails you halt the script.

Heres how:

function checkResult() {
	RESULT=$1
	if [ $RESULT -ne 0 ] ; then
		echo
		echo "!!!!!!!!!!!  Build Failed !!!!!!!!!!!!!!!!!"
		echo
		exit $RESULT
	fi
}

You call it like this:

./someCommandOrScript.sh
checkResult $?
  • Share/Bookmark

bash
code
linux commands
sysadmin

Comments (0)

Permalink

Edit GMail messages using Vim

Ok, why would you want to do this ?

Because you can.

1) Install this add-on which allows you to edit text areas in firefox using an external editor:

https://addons.mozilla.org/en-US/firefox/addon/4125

2) Install VIM

ftp://ftp.vim.org/pub/vim/pc/gvim72.exe

3) Setup the plugin to use vim (addOns->its all text addon->options)

4) make sure gmail is using “plain text” as editing – otherwise its not a text area, but some mad iframe.

6) Happy Days!

  • Share/Bookmark

bash
sysadmin

Comments (2)

Permalink

Read in a list of files and loop over them in bash

Needed to do this and after a bit of looking around (Bash scripting) came up with this:


#!/bin/bash

FILE_LIST_SOURCE=listoffiles.txt
DEFAULT_FILE="some.default.file"

[ -f $FILE_LIST_SOURCE ] && LIST_OF_FILES=$(cat $FILE_LIST_SOURCE)

LIST_OF_FILES=${LIST_OF_FILES:-$DEFAULT_FILE}

#echo -e "\\nLIST_OF_FILES:\\n$LIST_OF_FILES"

echo "List of files:"
for i in $LIST_OF_FILES; do
    echo $i
done


  • Share/Bookmark

bash
sysadmin

Comments (0)

Permalink

Python!

Wanted to find all files which contained a specific string and then extract a part of the line we were interested in.

First the GREP:

grep -R --include=*.vm  * > results.txt

then run this python script:

import re
for line in open('editablecomponents.txt'):
	match = re.search(r'#editableComponent\("(.*?)"', line)
	if match:
		print match.group(1) + "Display.vm"
  • Share/Bookmark

bash

Comments (0)

Permalink