Blog

Terminitor: Hasta la vista redundant commands!

By | February 22nd, 2011 at 5:02PM

Photo Courtesy of Flickr user Digital_Rampage

I frequently change my development environment on my laptop. I have one setup for different projects I’m working on at Engine Yard and others for projects I work on in my free time. It’s a big pain to always have to manually set up the development environment. I always wished there was a way to just automate it all: loading up the applications I wanted, then setting up my application consoles, database interfaces and monitoring the test output of the project.

Thankfully there is Terminitor, a project maintained by Arthur Chiu, of the Padrino team. Terminitor has made my life more simple. Currently Mac OS X Terminal, Mac OS X iTerm and KDE Konsole are the main cores that it works for. To all the Windows users who’ve fallen in love with Rails Installer, if you’re starting to experience the pain of repeatedly setting up your environment, I suggest you go fork Terminitor so that it can give you some love too.

There have been some cool changes since the creation of the Terminitor gem. One change is the addition of the iTerm Core, which has been great, especially with the release of iTerm2. I know I am one of many people who have switched over from Terminal to it. The second major change is the addition of the Ruby DSL. Before you had to create your Termfiles using a YAML syntax that looked something like this:

# ~/.terminitor/foo.yml
# you can make as many tabs as you wish...
# tab names are actually arbitrary at this point too.
---
- tab1:
- cd ~/foo/bar
- gitx
- tab2:
- mysql -u root)
- use test;
- show tables;
- tab3: echo "hello world"
- tab4: cd ~/baz/ && git pull
- tab5:
- cd ~/foo/project
- autotest

Some people might like using this syntax. If you are one of these people, you can enabled it by using $ terminitor edit foo --syntax yml. However, the newer Ruby DSL Syntax is much nicer and allows you to use it with a lot more complicated behavior such as window creation and setting up blocks that can be executed before loading a project.

A simple example that I think many people will find useful is starting up the server, tailing the log and opening the project up in their favorite text editor. Currently, my favorite text editor is Textmate, but I’m transitioning into the wonderful world of MacVim.

window do
  before { run 'cd ~/Projects/test' }
 
  tab "mate .", "passenger start"
 
  tab "tail -f log/passenger.3000.log"
 
  tab "open http://localhost:3000"
end

“But wait, Danish didn’t you read Rails AntiPatterns?! You’re supposed to have tests!” Yes, I know TDD is very important and I’m working on that. A good example of using Terminitor with tests is the Terminitor project itself. Another cool Terminitor feature is the ability to fetch Github Projects. One caveat is that you need to have the github-gem installed. All you have to do then is $ terminitor fetch achiu terminitor once the repo is cloned terminitor will automatically run the setup block that is in the Termfile for you.

# Terminitor Termfile
 
setup 'bundle install'
 
run 'watchr test.watchr'
tab "irb"
tab "open 'http://www.github.com/achiu/terminitor/issues'"

As you can see there is a watchr file that we run in one of our tabs so that every time we make a change to any of our files, the test corresponding with it will run and notify us if anything goes wrong.

Now that I’ve highlighted the features of Terminitor that I’ve found most useful, I suggest that you head over to the github page to check it out for yourself and figure out other things you can do with it to make your life easier.

One thing you might enjoy is Termfile, a new project on github that I created. This was inspired by gitignore, a project from Chris Wanstrath (aka defunkt). I know all of you Terminitor users out there have some really cool Termfiles that the rest of us can utilize. I know the rest of you will start creating some really useful ones. So, fork the Termfile project and add your Termfile in the appropriate directory so that others can find and use them for their projects too.

  • artemave

    tmux or screen – would be the real answer to your pain.

  • http://danishkhan.org Danish Khan

    Interesting I use screen, but I don't think it can automate a setup for me. I'm not sure about tmux I know a lot of people use it. iTerm2 seems to do the job for me though.

  • artemave

    Meet https://github.com/jondruse/screeninator and https://github.com/aziz/tmuxinator

    The fundamental difference between tmux/screen and terminal is that the former creates session which you can then detach (and later attach) from a terminal. This, for instance, makes it possible to work on remote machine without fear of loosing all your windows if connection drops. Of course, to benefit from it, there should be no gui tools involved in your setup. But that is a good thing anyway.

  • http://danishkhan.org Danish Khan

    Ahh, awesome. I'll check those two projects out.