I just knocked up a quick Ruby script to automate some of the steps I always do when starting work on a Rails project, namely:
– open an iTerm tab running script/server
– open an iTerm tab running script/console
– open an iTerm tab running autotest
– open an iTerm tab running a shell window
– launch Safari on localhost:3000 for testing.
Customise this little script to suit your own needs. You’ll need to install the rb-appscript gem to start with, and obviously this only applies to OS X users.
#!/usr/bin/env ruby
require 'rubygems'
require 'appscript'
RAILS_PROJECT_PATH = "~/path_to_your_rails_project" # Customise this
def create_iterm_tab( command = "" )
@iterm ||= Appscript::app( 'iTerm' )
session = @iterm.current_terminal.sessions.end.make( :new => :session )
session.exec( :command => 'bash -l' )
session.write( :text => "cd #{RAILS_PROJECT_PATH}" )
session.write( :text => command ) unless command.nil?
end
def launch_browser( url = "http://localhost:3000")
@safari ||= Appscript::app('Safari')
@safari.open_location(url)
end
create_iterm_tab("./script/server")
create_iterm_tab("./script/console")
create_iterm_tab("autotest")
create_iterm_tab()
sleep(5)
launch_browser()
The sleep(5) is in there to give time for the server to spin up before launching the browser.
Now put all this in a file called “launch_project.command” on the Desktop, and chmod +x it to allow it to allow it to execute when double-clicked.
I got some tips from Dribblings of a Deranged Hermit .
Happy New Year!
blog comments powered by Disqus