Sunday, June 22, 2008

Lazy Rails Development with Shell Function Shortcuts

I love screencasts, and on every screencast I see that texmate editor I'm so jealous of. I work at a startup so it'll be a while before we'll dish the cash out for a mac, as much as I'd like one, its not in the cards right now.

Once of the things I like the most about that editor is the ability to seemlessly jump between different files in your rails app. I find myself doing certain commands _constantly.

One tip is to create shell functions for your most commonly used commands

ruby script/server #rss
mongrel_rails start -d -e development -p 3000 #mrd_start
mongrel_rails stop #mrd_stop
vim app/controller/some_controller.rb #rvim c some
vim app/models/post.rb #rvim m post
vim app/helper/posts_helper.rb #rvim h posts
vim app/views/posts/_form.rhtml #rvim v posts/_form.rhtml
mongrel_rails cluster::stop #mrc stop
mongrel_rails cluster::start #mrc start


Here is the code (feedback appreciated)

function rss
{
command ruby script/server
}
function mrd_start
{
command mongrel_rails start -d -e development -p 3000
}
function mrd_stop
{
command mongrel_rails stop
}
function mrd_restart
{
command mongrel_rails stop&&mongrel_rails start -d -e development -p 3000
}
function mrc_start
{
command mongrel_rails cluster::start
}

function mrc_stop
{
command mongrel_rails cluster::stop
}
function mrc_restart
{
command mongrel_rails cluster::stop&&mongrel_rails cluster::start
}

function rvim
{
case "$1" in
'c')
command vim app/controllers/$2_controller.rb
;;
'v')
command vim app/views/$2
;;
'm')
command vim app/models/$2.rb
;;
'h')
command app/helpers/$2_helper.rb

esac
}





Hope this helps!

No comments: