I'm about to show you how I roll with iTerm and Rails application development. It may seem a little screwy to a proficient TextMate users, but hear me out. I know my way around Vim. That makes me very productive with it. My problem with TextMate, is that it isn't totally about getting away from the mouse, clicking, and pressing arrow keys. Don't get me wrong; they get a *lot* right.
"Damn, I though Rob was going to blog about something other then his aversion to non-home row hand positions!"
My whole Mac life changed when iTerm got tabs. It really got me to a place where I didn't miss Linux as bad. But still, opening tabs, logging into servers, changing directories, and starting services, still takes time. When you bounce between projects as often as I do, it becomes a real problem. I had to figure out a way to script some of this.
So, here's what that quest produced. It's a shell script, that runs AppleScript (what a goofy language!) and gets my iTerm window all set up to jump into a project after having been away for a bit. In other words, it opens up tabs and executes various commands in each tab, all following a single press of the "return" key. Check it out:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
#!/bin/sh
if [[ $# == 0 ]]; then
PROJECT_DIR=$PWD
elif [[ $# == 1 && -d "$1" ]]; then
PROJECT_DIR="$@"
else
print "usage: iterm.sh [rails project directory]"
return 1
fi
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 "app"
write text "cd \"$PROJECT_DIR\"/app"
write text "clear; ls"
end tell
launch session "Default Session"
tell the last session
set name to "app"
write text "cd \"$PROJECT_DIR\"/app"
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 "yell"
write text "cd \"$PROJECT_DIR\""
write text "cd log"
write text "tail -f yell.log"
end tell
end tell
end tell
eof |
To use, save to an executable file and run from the same directory as your Rails project. Pass the project directory as an argument to the script.
$ iterm tupleshop.blog
then watch what happens:

I use the first two tabs as my primary work areas. I usually have the Vim screen split once or twice. Any more editor's open and I usually loose track of where things are. The functions of the remaining tabs should be evident. The only strange one is named "yell." That's where I tail my stupid simple log file (that I blogged about once) called yell.log.
So, if you find this solution, or the problem I'm trying to solve, interesting, please share your ideas.
(I'd love to meet a TextMate pro and swap for Vim training sessions. Although, I know from experience that getting fast is not something you do in one sitting.)




