Rails 3 bash aliases and .irbrc configs


I’ve been upgrading some apps and gems to the latest and greatest Rails 3. I’ve taken the time to update my ~/.bash_aliases and ~/.irbrc files to be both Rails 3 and Rails 2.x compatible. See below for the code.


# rails 3 shortcut 'r'
alias r='rails'

# launching console/server
sc () {
  if [ -f ./script/rails ]; then 
    rails c $@
    ./script/console $@

sg () {
  if [ -f ./script/rails ]; then
    rails g $@
    ./script/generate $@

ss () {
  if [ -f ./script/rails ]; then 
    rails s $@
    ./script/server $@

sspe () {
  if [ -f ./script/rails ]; then 
    sudo rails s -p80 $@
    sudo ./script/server -p80 $@

# database migrate
alias rdbm='rake db:migrate'

# tests
alias rspec='rake spec'

# rails logs, tailing and cleaning
alias tdl='tail -f ./log/development.log'
alias ttl='tail -f ./log/test.log'
alias ctl='> ./log/test.log'
alias cdl='> ./log/development.log'


require 'rubygems' rescue nil
require 'wirble'
require 'hirb'
require 'ap'

# load wirble

# load hirb

IRB.conf[:AUTO_INDENT] = true

if ENV.include?('RAILS_ENV')
  if !Object.const_defined?('RAILS_DEFAULT_LOGGER')
    require 'logger'
    Object.const_set('RAILS_DEFAULT_LOGGER', Logger.new(STDOUT))

  def sql(query)
  if ENV['RAILS_ENV'] == 'test'
    require 'test/test_helper'

# for rails 3
elsif defined?(Rails) && !Rails.env.nil?
  if Rails.logger
    Rails.logger =Logger.new(STDOUT)
    ActiveRecord::Base.logger = Rails.logger
  if Rails.env == 'test'
    require 'test/test_helper'
  # nothing to do

# annotate column names of an AR model
def show(obj)

puts "> all systems are go wirble/hirb/ap/show <"

Note that if your’e using Bundler in your Rails app, AND use gems in your ~/.irbrc file AND attempt to start the Rails console; you’ll get errors/warnings on requiring them UNLESS you define them in your Gemfile. I use a ‘development’ group in my Gemfile for these, like so.


group :development do
  gem "wirble"
  gem "hirb"
  gem "awesome_print"

platforms :ruby_18 do
  gem 'ruby-debug'

platforms :ruby_19 do
  gem 'ruby-debug19'
September 19, 2010 18:33 by

13 comments so far

  • photo of Daniel Kristensen Daniel Kristensen Sep 23, 2010

    That’s some great tweaks :-D Thanks

  • photo of Heiko Seebach Heiko Seebach Sep 23, 2010


    if you start irb without Rails environment, it crashes at

    “elsif !Rails.env.nil?”

    because Rails is not defined.

    You could change it like this: elsif defined?(Rails) and !Rails.env.nil? if Rails.logger Rails.logger =Logger.new(STDOUT) ActiveRecord::Base.logger = Rails.logger end if Rails.env == ‘test’ require ‘test/test_helper’ end else

    1. nothing to do end

    cu, Heiko

  • photo of matt matt Sep 23, 2010

    Thanks for the heads up Heiko! I’ve updated the post and the gist with this fix.

  • photo of Stephen Touset Stephen Touset Sep 23, 2010

    The line `gem RUBY_VERSION.include?(‘1.9’) ? ‘ruby-debug19’ : ‘ruby-debug’` in your Gemfile is fundamentally broken. It will cause the Gemfile.lock to be vary upon the architecture `bundle install` is run on, and this should not happen, since the Gemfile.lock should be committed to your repository.

    Instead, use the “platform” block provided in Bundler.

  • photo of Matt Matt Sep 23, 2010

    Thanks Stephen (again) i’ve updated the post with the fix

  • photo of Brooke Kuhlmann Brooke Kuhlmann Sep 23, 2010

    Nice, write up, thanks. I’ve incorporated some of your ideas in my own .bash_profile file via my Mac OS Setup (http://github.com/aeonscope/macos_setup) project. You might find some of my settings to your liking as well. BTW, you might want to change the following alias commands since they clobber native Mac OS binaries of the same name: <ol> <li>rs</li> <li>dbm</li>

  • photo of Matt Matt Sep 24, 2010

    Nice one Brooke, I’ve cobbled together something like this on my for setting up my own mac development machines, only using bash and git.

    I’ve been meaning to standardize it more, and would consider creating a brew for it. I check out your git repo for some ideas.

  • photo of Mark Wilkinson Mark Wilkinson Sep 24, 2010

    I might be missing something, but it looks like the functions in your .bash_aliases file are using zsh syntax to pass the arguments through ($argv). For bash I think you should be using “$@”.

  • photo of matt matt Sep 28, 2010

    Thanks Mark, well spotted, I’ve updated that now to the $@ format instead.

  • photo of lucapette lucapette Nov 13, 2010

    Your gem development set is exactly what i was looking for.

Leave a comment