Handy iTerm Shortcut
So each time I go to code in a rails app I open up three tabs: one for script/server, one for autotest and one for general commands like script/generate and such. Let’s say I want to open up tinye, a project I’m working on at work. I have to do the following:
cd sites/nd/tinye.git script/server # new tab cd sites/nd/tinye.git a #that is my shortcut for autotest -rails # new tab cd sites/nd/tinye.git
I got a bit tired of this, so based on some scripts I saw around the interwebs, I put together the one below:
#!/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 # how to make new terminal (make new terminal) osascript <<-eof tell application "iTerm" tell the last terminal activate current session tell the last session set name to "server" write text "cd \"$PROJECT_DIR\"" write text "ss" end tell launch session "Default Session" tell the last session set name to "autotest" write text "cd \"$PROJECT_DIR\"" write text "a" end tell launch session "Default Session" tell the last session set name to "app" write text "cd \"$PROJECT_DIR\"" write text "open http://localhost:3000/" end tell end tell end tell eof
I put this in /bin, named iterm.sh, and made sure it was executable (
chmod u+x ~/bin/iterm.sh). Then I threw the following in as aliases (/.bash_profile for me):
alias r='iterm.sh $1' alias ss='script/server' alias sc='script/console' alias a='autotest -rails'
This allows me to open the same project I talked about earlier by simply typing:
Instantly, I get three tabs in iTerm (server, autotest and blank) and an open browser window on localhost:3000. Thought I would share it here to spark other ideas like this. Also, I’m curious if others have similar things (or cooler things). Below is quick and dirty screencast that shows it in action.