Archives for July 2010

Easy interaction with Ruby code

I really wanted to be able to interact with some Ruby code I was writing in a back and forth with TextMate. So I added this command as "Interact" (and bound to Cmd+Ctrl+R) to my Ruby bundle:

#!/usr/bin/ruby

require 'rubygems'
require 'appscript'

$TERM = Appscript::app( 'iTerm' )
$SESSION = $TERM.current_terminal.sessions.end.make( :new => :session )
$SESSION.exec( :command => 'bash -l' )
$SESSION.write( :text => "/usr/bin/irb -r #{ENV['TM_FILEPATH']} && exit" )
$TERM.activate

Since I use iTerm and always have at least one window open what this does is to tell iTerm to spawn a new window with a bash shell and then execute IRB, requiring my code.

The net result is that hitting Cmd+Ctrl+R gives me my code in an IRB session ready to test via the REPL. I can poke around, hit Ctrl+D to get rid of the IRB session, go back to TextMate & make some changes, then hit Cmd+Ctrl+R to get a new IRB with the updated version ready to test.

I'm finding it makes for a very easy back-and-forth.

13/07/2010 11:22 by Matt Mower | Permalink
More about: