Current git branch and git autocompletion in bash

First put the following script somewhere, like ~/git_completion.sh and chmod +x it.

Then add this line to your ~/.bash_profile:

. ~/git_completion.sh

Finally, if you want to pretty up your prompt as above, then add this:

export PS1=’\h:\W \[\e[1;32m\]$(__git_ps1 “[%s]“)\[\e[0m\] > ‘

You can also install git from http://code.google.com/p/git-osx-installer/ (Thanks Jon)

Or on ubuntu install a package called “git-completion” (Thanks Juan)

Share

A proper shell in windows

Thanks to a posting on our mailing list I am trying out mintty, a tty shell emulator for windows which runs on top of cygwin.

So far so good, feels like the real deal.

You can install it by running “setup.exe” in the cygwin folder and install it from the package list under “shells”.

I added a couple of lines to my ~/.bash_profile

export PS1="\W> "
alias clear='echo -e "\033c"'

As there didn’t seem to be a default “clear” command to clear the terminal. Got the trick from here. Also good is The tips and tricks page

To get a nice “Bash prompt here” you can install the chere package from the cygwin setup (same as above) and then run:

chere -i -c -t mintty -s bash

One oddity I’ve found is that if you execute a batch file which uses CMD.exe, CTRL+C doesn’t seem to work. It breaks out of the program but then output still appears! So you need to run .sh files in there.

Share

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

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