Probably the one thing I have found most daunting in ruby on rails development is learning the command line and it’s unix counterparts such as shell scripting. Unfortunately, to be a good rails developer you need to know your way around the terminal. This post is not about setting up ruby on rails, but rather about enhancing your terminal for ruby on rails development.
iTerm2
Perhaps the first place to start is with upgrading your terminal. iTerm2 is a terminal replacement where the “focus is on performance, internationalization, and supporting innovative features that make your life better.” So yeah, download that.
oh-my-zsh
While Mac ships with Bash as your default shell (terminal), it also allows you to change to an arguably better shell called zsh (Z-shell). Here is a free eBook on zsh if you would like to enlighten yourself on it.
Anyway, some nice people have come together and built a set of defaults for your zsh called oh-my-zsh. Not only that, but it allows you to pick and install extra plugins and themes (yes, the terminal is becoming more like a text editor). From their Github page:
oh-my-zsh is:
“A community-driven framework for managing your zsh configuration. Includes 40+ optional plugins (rails, git, OSX, hub, capistrano, brew, ant, macports, etc), over 80 terminal themes to spice up your morning, and an auto-update tool so that makes it easy to keep up with the latest updates from the community.”
I suggest you go to their page and follow their instructions on how to setup.
Optimise oh-my-zsh for Ruby on Rails
As you would have read on the oh-my-zsh page, all of your configuration can be found in the .zshrc file, which for me is located in ~/.zshrc. Use your favourite text editor to open this file.
The first thing you should do is create an alias to re-open this file for future configuration. On line 10 or something they have started this for you. Here is mine (note that subl = Sublime Text 2, which is my text editor):
alias zshconfig="subl ~/.zshrc"
alias ohmyzsh="subl ~/.oh-my-zsh"
So now if I type “zshconfig” into my terminal this configuration file will appear, ready for a quick edit.
In terms of themes, the one you can see in the picture is one that I created myself. LOL jks, it is a default that I subtly changed. If you go here to look at all the themes, you will find that I am using a slightly edited version of “bira”. Basically I removed that horse shoe thing at the front, which, under the font I use (12p Monaco), looked rubbish.
To edit the theme I just cloned the bira theme under a new name (themes are in .oh-my-zsh/themes/), and changed the .zshrc file to point to mine:
Next we add a quick line to the bottom to make RVM work correctly:
Finally you should add some of the plugins that Rails development uses. Here are the ones I added along with their functionality:
## rails3
# rc - rails console
# rd - rails destroy
# rdb - rails dbconsole
# rdbm - rake db:migrate db:test:clone
# rg - rails generate
# rp - rails plugin
# rs - rails server
# rsd - rails server --debugger
# devlog - tail -f log/development.log
# rdm - rake db:migrate
# rdr - rake db:rollback
## bundler
# be - bundle exec
# bi - bundle install
# bu - bundle update
## rvm
# rb18 [GEMSET]: shortcut for rvm use ruby-1.8.7-p334@GEMSET (with gemset completion)
# rb19 [GEMSET]: shortcut for rvm use ruby-1.9.2-p180@GEMSET (with gemset completion)
# rubies: list installed rubies
# gemsets: list gemsets for currently active ruby
# gems: list gems available in currently active gemset
## git
# Too many aliases to mention...I suggest looking at them in your editor (~/.oh-my-zsh/plugins/git/git.plugin.zsh)
##ruby
# rfind - find ruby files in directory
Make the most of your shiny new toy
This is only the start of turning your terminal into the cheetah of productivity. From here you should be extending your list of aliases, as well as adding custom functions and scripts. A good way to see what other people have done is simply to check on Github. People seem to love showing off their dotfiles (the name for all these terminal configuration files).
I also suggest looking at how zsh can improve productivity – perhaps learn some of these tricks!
As usual, Tweet or Like this if it was of any use. Cheers
