Create the new command (by ripping off the standard one)
- Hop in to TextMate (it’s already running, isn’t it?)
- Select “Bundles>Bundle Editor>Edit Commands” from the menu
- Expand the Ruby bundle, and select the “Run” command
- Click the little ‘double-plus’ at the bottom, which duplicates the current command
- Name the new command ‘Run Last’
Make it use our special file
With “Run Last” still selected, paste this in to the text area:
export RUBYLIB="$TM_BUNDLE_SUPPORT/RubyMate${RUBYLIB:+:$RUBYLIB}"
export TM_RUBY=$(which "${TM_RUBY:-ruby}")
export TM_FILEPATH=`cat "$TM_PROJECT_DIRECTORY/.tm_last_run_ruby"`
cat "$TM_FILEPATH" | "${TM_RUBY}" -- "$TM_BUNDLE_SUPPORT/RubyMate/run_script.rb"
What we’re doing is reading a hidden ‘.tm_last_run_ruby’ file to figure out what file to run.
Get the special file written out
Now go back to the “Run” command, and change it to this:
export RUBYLIB="$TM_BUNDLE_SUPPORT/RubyMate${RUBYLIB:+:$RUBYLIB}"
export TM_RUBY=$(which "${TM_RUBY:-ruby}")
echo "$TM_FILEPATH" > "$TM_PROJECT_DIRECTORY/.tm_last_run_ruby"
"${TM_RUBY}" -- "$TM_BUNDLE_SUPPORT/RubyMate/run_script.rb"
This writes out the file about to be run to the special ‘.tm_last_run_ruby’ file.
Enjoy!
- Assign a key combo to “Run Last”. I use Command-Ctrl-R.
- Delete the scope in “Run Last” - we want to be able to run it anywhere and everywhere.
- Ignore ‘.tm_last_run_ruby’ in your source control, lest it bug you.
- Run a Ruby file like normal, then go anywhere and re-run it with impunity.


