Monday, May 21, 2012

tmux for Ruby on Rails

A couple of weeks ago I stumbled on tmux as a way to manage the proliferation of terminal windows when doing Ruby on Rails development.

My Rails 3.2 development environment is a Ubuntu guest OS running on a VirtualBox VM hosted on my Windows 7 desktop. Since I wanted to stay on my Windows desktop most of the time, rather than interact with Ubuntu through the somewhat laggy Virtualbox display, I would ssh into the Ubuntu guest using a Cygwin terminal (mintty). And being a good ol' Rails fanboy, I started using Vim and all its plugins as a really nice Rails/Ruby editor.

However: once I got a couple of Vim editors, a rails server, a rails console, a log file tail, and a Guard or RSpec session all running at once, plus the Ruby on Rails tutorial and Rails app open in browser windows, my Windows desktop started to look like Mah Jongg game in full swing. I was spending more time tabbing around looking for the right window than actually learning anything!

Tmux brings some order to that chaos. According to the tmux man page, "tmux is a terminal multiplexer: it enables a number of terminals to be created, accessed, and controlled from a single screen." After some tweaking and fiddling, this is the layout I've settled on:

I've split a single "window" named "rails" into to three "panes": top-left I have Guard running Rspec tests, bottom-left I have the Rails server, and at right my main Vim editing session. On a second window named "logs" I have a tail on the Rails server log file.

The cool thing about this is that it all starts up automatically when I run a shell script that instructs tmux to set up the windows and start all of the processes I need for my Rails development session. Tmux will even maintain the session in case my terminal connection dies.

I relied on these excellent introductions to TMUX to get started:
Here's the shell script I cobbled together to create that session:

And my .tmux.conf file:


  1. Any idea how to get the red/green from guard&rspec into the tmux status bar?

    1. Hi Gordon, sorry, no, I don't know, but that's a very cool idea! Next time I'm messing around with tmux, I'll have a look.

  2. I'm new to this .. can you please tell me how do you run your rumble shell script?

    1. Hey Ketan, thanks for commenting on my blog post! This one is an oldie, and I haven't run tmux or rails or any of that stuff for a loooong time! As far as I can remember, it should "just run" in a bash shell. I wish I could help you more. I'd suggest you copy the script and the tmux config file to your environment and play around with it. THat's how I developed it in the first place.

      Best of luck to you!


Note: Only a member of this blog may post a comment.