Textmate script to restart mongrel

I often find myself needing to restart the rails app I am working on while in Textmate. Sure, its easy enough to switch to a terminal window and hit up-arrow, but since Textmate is a wonderfully developer friendly app, I decided to see what I could do about automating a common task.

In Textmate go to Bundles -> Bundle Editor -> Edit Commands

Use the + at the bottom to create a new Command

This gives you a blank template for a new command. The command editor gives you control over several aspects of your current working document and project. Since this is an app restart for development purposes, I choose to save all files before executing the command. Then, I just put in a few shell commands that will be executed directly. I like to do a clean restart so that the same script works even if this is the first time starting it up:

echo "Restarting the App..." 
cd "$TM_PROJECT_DIRECTORY" 
mongrel_rails stop
mongrel_rails start -d -p4040

This command takes no input, and puts the output into a tooltip. Finally, I need to select a key combination. cmd-R is taken, so I settled on cmd-G (for GO!).

That’s it. My very own custom command in Textmate in under 5 min. I leave the “Stop App” command as an exercise for the user.

Posted by Adeh Mon, 03 Dec 2007 22:40:00 GMT