My .irbrc

I haven’t seen very many .irbrc files lying around on the internet. Examples, sure, I’ve seen examples, but nothing anyone would actually use. Maybe no one has taught me that things like .irbrc files are not interesting. I think they would be. I want to see more.

Here’s mine:

IRB_START_TIME = Time.now

ARGV.concat [ "--readline" ]

require 'pp'
require 'rubygems'
require 'duration'
require 'wirble'
require 'irb/completion'
require 'irb/ext/save-history'

IRB.conf[:PROMPT][:SHORT] = {
  :PROMPT_C=>"%03n:%i* ",
  :RETURN=>"%sn",
  :PROMPT_I=>"%03n:%i> ",
  :PROMPT_N=>"%03n:%i> ",
  :PROMPT_S=>"%03n:%i%l "
}

IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
IRB.conf[:PROMPT_MODE] = :SHORT

Wirble.init(:skip_prompt => true, :skip_history => true)
Wirble.colorize

at_exit { puts Duration.new(Time.now - IRB_START_TIME) }

def clear
  print "e[He[2J"
end

A couple of notes:

  1. Wirble colorizes return values in irb, and does a pretty good job at it. It also changes the prompt and the behavior of irb’s history in ways I don’t like; the Wirble.init line takes care of those problems.
  2. I was always trying to clear the screen with clear. I had to make it happen on my own. If I could suppress the nil that gets displayed afterwards, I would.
  3. The short prompt I make there is sort of a halfway between the standard prompt irb(main)001:0> and the simple prompt >>. I want line numbers and indent levels! I want to know where I am.
  4. I also want to know when I am. So I set IRB_START_TIME and use the Duration gem and at_exit to tell me how long my irb sessions are. It is totally worthless, but I love it. It makes me feel productive. Have a look:
mvb:~ cms$ irb
001:0> "wait a minute"
"wait a minute"
002:0> exit
20 seconds
mvb:~ cms$

I couldn’t wait a full minute.

4 Comments »

  1. bryanl said,

    July 14, 2007 @ 4:29 am

    I use the one I posted, now I’ll take the good parts out of yours and merge them into mine :)

    http://smartic.us/2007/3/7/i-present-my-irbrc

  2. M'enfin ?!? said,

    November 30, 2007 @ 5:46 pm

    IRB, un outil à (re)découvrir…

    IRB est un outil génial pour tester rapidement un truc en Ruby. C’est une sorte d’interpréteur Ruby qui fonctionne comme un shell : vous tapez une ligne de Ruby, irb l’interprête et vous donne le résultat, vous tapez une autre ligne, irb…

  3. Improved irb configuration | tail -f findings.out said,

    July 18, 2009 @ 8:19 pm

    [...] I came across a number of additional customizations that have proved quite useful. I took this page’s suggestions mostly verbatim in formulating mine. This page was also helpful. Here’s my [...]

  4. raf said,

    January 30, 2010 @ 9:29 pm

    I like Ctrl-L more than “clear” (but I think this only works in Mac and Linux)

RSS feed for comments on this post · TrackBack URI

Leave a Comment