My Rails project workspace script
When I’m ready to start a session working on Tracks on my MacBook, I open up iTerm, and type:
Last login: Tue Oct 9 02:44:39 on ttyp6 Welcome to Darwin! LukeBlackBook:~ lmelia$ cd devprojects/tracks/ LukeBlackBook:~/devprojects/tracks lmelia$ workspace
And then, the following happens:
- A new iTerm session opens, with four tabs:
- A tab running script/server
- A tab running script/console
- A tab running autotest
- A tab with a prompt in the project directory
- A new TextMate window opens with the project tree in it’s drawer.
- A new Firefox tab opens with the http://0.0.0.0:3000/
The magic is enabled by this combination of shell and applescript:
#!/bin/sh
if [[ $# == 0 ]]; then
PROJECT_DIR=$PWD
elif [[ $# == 1 && -d “$1″ ]]; then
PROJECT_DIR=”$@”
else
print “usage: workspace.sh ”
return 1
fi
PROJECT_NAME=`basename $PROJECT_DIR`
osascript <<-eof tell application "iTerm" make new terminal tell the last terminal activate current session launch session "Default Session" tell the last session set name to "$PROJECT_NAME" write text "cd \"$PROJECT_DIR\"" write text "clear; ls" end tell launch session "Default Session" tell the last session set name to "server" write text "cd \"$PROJECT_DIR\"" write text "./script/server" end tell launch session "Default Session" tell the last session set name to "console" write text "cd \"$PROJECT_DIR\"" write text "./script/console" end tell launch session "Default Session" tell the last session set name to "autotest" write text "cd \"$PROJECT_DIR\"" write text "autotest" end tell end tell end tell eof open http://0.0.0.0:3000/ mate $PROJECT_DIR [/code] Props to Rob Orsini for the inspiration for this. My version has just minor tweaks from his original.
Yay! Thanks Luke.
October 9th, 2007 at 11:48 pm