Luke Melia

software dev

October 9, 2007

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:

CODE:
  1. Last login: Tue Oct  9 02:44:39 on ttyp6
  2. Welcome to Darwin!
  3. LukeBlackBook:~ lmelia$ cd devprojects/tracks/
  4. 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:

CODE:
  1. #!/bin/sh
  2.  
  3. if [[ $# == 0 ]]; then
  4.   PROJECT_DIR=$PWD
  5. elif [[ $# == 1 && -d "$1" ]]; then
  6.   PROJECT_DIR="$@"
  7. else
  8.   print "usage: workspace.sh [rails project directory]"
  9.   return 1
  10. fi
  11. PROJECT_NAME=`basename $PROJECT_DIR`
  12.    
  13. osascript <<-eof
  14.   tell application "iTerm"
  15.  
  16.     make new terminal
  17.  
  18.     tell the last terminal
  19.  
  20.       activate current session
  21.  
  22.       launch session "Default Session"
  23.  
  24.       tell the last session
  25.           set name to "$PROJECT_NAME"
  26.           write text "cd \"$PROJECT_DIR\""
  27.           write text "clear; ls"
  28.       end tell
  29.  
  30.       launch session "Default Session"
  31.       tell the last session
  32.           set name to "server"
  33.           write text "cd \"$PROJECT_DIR\""
  34.           write text "./script/server"
  35.       end tell
  36.  
  37.       launch session "Default Session"
  38.       tell the last session
  39.           set name to "console"
  40.           write text "cd \"$PROJECT_DIR\""
  41.           write text "./script/console"
  42.       end tell
  43.  
  44.       launch session "Default Session"
  45.       tell the last session
  46.         set name to "autotest"
  47.         write text "cd \"$PROJECT_DIR\""
  48.         write text "autotest"
  49.       end tell
  50.  
  51.     end tell
  52.   end tell
  53. eof
  54. open http://0.0.0.0:3000/
  55. mate $PROJECT_DIR

Props to Rob Orsini for the inspiration for this. My version has just minor tweaks from his original.

One Response to “My Rails project workspace script”

  1. a gravatar Scott Bellware chimed in:

    Yay! Thanks Luke.

Leave a Reply

LukeMelia.com created 1999. ··· Luke Melia created 1976. ··· Live With Passion!