Elia Schito

start/stop Rails server with TextMate

In Mongrel, Rails, Rails Server, Ruby, Ruby on Rails, Ruby snippets, TextMate, TextMate Bundle on June 18, 2007 at 11:51 am

Open your Bundle Editor and make two new commands with:

  • no input
  • tooltip output
  • scope selector: source.ruby.rails

Update! download the tmCommand:
TextMate “start/stop Rails server” command
(download and rename as “start/stop rails server.tmCommand”, this is due to the wordpress security policy)

Key Equivalent: alt+shift+S

Start command:

cd $TM_PROJECT_DIRECTORY

./script/server -d

Stop command:

#!/usr/bin/env ruby

pid = File.open ENV['TM_PROJECT_DIRECTORY']+'/tmp/pids/mongrel.pid' rescue puts("not started")

puts "stopped" if pid and `kill #{pid.read}`

then find a tab trigger or key combination that fits these commands.

  1. Hi, thanks for releasing this

    It’s unclear to me what to name the file as. Do we create two copies of the file, one called “Start Rails Server.tmCommand”, and another, “Stop Rails Server.tmCommand”?

  2. Thanks! You’re awesome!

  3. OK… I tried this and it was PRETTY cool… but I wasn’t able to use ruby-debug with this solution (due to the lack of a command window)

    I came up with this alternative:

    #!/usr/bin/osascript
    tell application “Terminal”
    activate
    do script “cd $TM_PROJECT_DIRECTORY && script/server”
    end tell

    http://pastie.caboo.se/128984

    Puh-eace!

  4. Are you supposed to set TM_PROJECT_DIRECTORY somewhere?

  5. Thanks for this one, it starts nicely. But for some reason it doesn’t stop the server when calling it again.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: