A better script/server alias for Rails
Posted: August 13th, 2009 | Author: robincurry | Filed under: Uncategorized | Tags: bash, rails | 1 Comment »I’ve long had a bash alias for starting up script/server for a rails process that looked something like:
alias ss="./script/server"
This has worked all well and good, but I’ve been wanting more. I often find myself switching between projects and the time and effort it takes is just exhausting. I mean, think of all those keystrokes!

Inspired by @MikeG1′s tweet pining for a script/server to kill any other process running on same port, and a desire to make the switching process easier for myself, I came up with the following function that I added to my bash profile.
Now switching between rails apps is effortless. I can start the rails app from anywhere with no worries about conflicting processes (bye bye, you’ve been terminated) or even changing to the proper directory. Ahhh, my hands feel lighter already.
Enjoy!
function ss {
if [ "$1" ]; then
# cd to the rails app directory.
cd ~/proj/repos; # (update the repository root location to suit your needs)
if [ "$1" ]; then
cd `ls|grep $1|sort|tail -1`
fi
echo $(pwd)
fi
# kill any existing rails server processes.
ps -a|grep "ruby ./script/server"|grep -v "grep"|cut -d " " -f1|xargs -n 1 kill -TERM
# start the server.
ruby ./script/server
}
Popularity: 63% [?]