Tag Archive for 'terminal'

New Terminal tab with pwd

Just a quick snippet I’m using to open a new tab in Terminal. It accepts a single, optional argument which will override cd’ing to the working directory.

#!/usr/bin/env bash
 
if [[ $# -eq 0 ]]; then
	dir=`pwd`
else
	dir=$1
fi
 
/usr/bin/osascript \
-e "tell app \"System Events\" to tell process \"Terminal\" to keystroke \"t\" using command down" \
-e "tell app \"Terminal\" to do script \"cd $dir\" in front window" \
-e "tell app \"System Events\" to tell process \"Terminal\" to keystroke \"l\" using control down"

I’ve put the shell script in “/usr/local/bin” as this is in my $PATH. I’ve named the script “tab” so whenever in Terminal I can enter “tab” to open a new tab with the current working directory ready and waiting. Very useful when working with Rails and multiple shells.

Terminal, colour and Ruby

I use ruby for system administration tasks all the time and find a little colour always helps to highlight certain information. The only problem is I’ll forget which colour is represented by which number. The ruby script below prints out a nice box of all foreground and background colours. I’ve uploaded a screenshot of the output below so you can see how it looks. MORE »