Quick new tab from iTerm

One task I keep doing each day when I work on a Rails project is:

  1. launch iTerm
  2. cd to my rails project
  3. start script/server
  4. open a new tab
  5. cd to my rails project

You see the ugly, terrible, horrible time wasting duplicated task (cd to my rails project). I’m so sorry I kept doing this for so long and now admit it on my blog! Now it’s there forever and in 10 years my kids will Google my name and find this stupid thing and lose all faith in their father, my wife will leave me and I’ll quit programming. I’m sorry, really…

Well, to be sure founding a family won’t make me quit programming, I made a small shell script to make this less painful and more DRYfull:

tab() # new tab from current dir
{
osascript -e "
tell application \"iTerm\"
 tell the first terminal
  launch session \"Default Session\"
  tell the last session
   write text \"cd $(pwd)\"
  end tell
 end tell
end tell"
}

Place this in your ~/.bash_profile then type tab in your terminal window to see some magic happen.

Let me know if this is helpful to you!

5 Comments

Filed under Mac, rails, ruby

5 responses to “Quick new tab from iTerm

  1. Great shortcut, Marc. Thanks!

  2. Glad I could help Luke, I use it everyday.

    BTW, I ended up doing this a lot:

    tab; script/server

  3. Just what I needed. Thanks. To get rid of the ugly backslashes I just placed the script in a here doc:
    tab() { osascript <<SCRIPT
    tell application "iTerm"
    tell the first terminal
    launch session "Default Session"
    tell the last session
    write text "cd $(pwd)"
    end tell
    end tell
    end tell
    SCRIPT
    }

  4. SA

    TFS! I need to login to multiple machines everyday. This really came handy for connecting to them.
    —————
    #!/bin/bash
    for i in node1.edu node2.com node3.net node4.org
    do
    osascript -e ”
    tell application \”iTerm\”
    tell the first terminal
    launch session \”Default Session\”
    tell the last session
    write text \”ssh user@${i}\”
    end tell
    end tell
    end tell”
    done

  5. GK

    thank you so much. so useful

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s