My morning routine is pretty much always the same. My wife wakes me up, saying something about “late†that I can’t quite comprehend. I writhe about on the bed a bit trying to break free from the remaining tendrils of sleep. Finally, I look at my watch and spend a moment processing the numbers.
Shit. I have to go to work.
A 30 second shower later and I am in my car heading to the office. Luckily, Stephanie understands this process enough to get it started earlier enough for me to get to work on time. I roll into my office at the last possible moment though.
Okay. I have to get to work fast. Unlock my windows box, open my MacBook, launch Outlook on my windows box, launch iTerm on my MacBook. Have you seen the scene in office space where the main character is trying to get out of work before his boss asks him to work on the weekend? That is how I feel at about this point.
iTerm is finally up. Now, I just need to open 3 tabs and start my server, my rails console, and a tail of my development log.
Am I not a programmer? Can’t I make my Mac do all of this work for me? Of course I can.
listing for /usr/local/bin/rdev
#!/bin/zsh -f
if [[ $TERM_PROGRAM != iTerm.app ]]; then
open -a Terminal
return 0
fi
# First, get the directory for rails
if [[ $# == 0 ]]; then
ThisDirectory=$PWD
elif [[ $# == 1 && -d "$1" ]]; then
ThisDirectory=”$@”
else
print “usage: rdev [directory]”
return 1
fi
if [[ -e "$ThisDirectory/script/server" ]]; then
print “Starting Rails Dev Environment”
else
print “$ThisDirectory does not look like a rails app!”
return 1
fi
osascript <<-eof
tell application “iTerm”
make new terminal
tell the front terminal
activate current session
launch session “Default Session”
tell the last session
write text “cd \”$ThisDirectory\”"
end tell
tell the last session
write text “./script/server”
end tell
end tell
end tell
tell application “iTerm”
make new terminal
tell the front terminal
activate current session
launch session “Default Session”
tell the last session
write text “cd \”$ThisDirectory\”"
end tell
tell the last session
write text “./script/console”
end tell
end tell
end tell
tell application “iTerm”
make new terminal
tell the front terminal
activate current session
launch session “Default Session”
tell the last session
write text “cd \”$ThisDirectory\”"
end tell
tell the last session
write text “tail -f log/development.log”
end tell
end tell
end tell
tell application “iTerm”
activate
end tell
eof
Now, when I get in I use Quicksilver to open an iTerm in my development directory. Then I simply type “rdev” and I am ready to roll.
This code is thanks largely to the scripts available at http://xanana.ucsc.edu/xtal/iterm_tab_customization.html