Tab completion and history with irb and script/console

One thing I love about Ruby (and really miss when working in Java) is its interactive command line interpreter irb (or script/console if you’re using Rails). I really wish irb had tab completion and saved history configured by default out of the box. The good news is it’s easy to configure by creating a $HOME/.irbrc file with the following contents:

require 'irb/completion'
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
IRB.conf[:EVAL_HISTORY] = 1000
IRB.conf[:SAVE_HISTORY] = 1000
IRB.conf[:HISTORY_FILE] = File::expand_path("~/.irbhistory")

Now when I fire up irb or script/console I get full readline support including tab completion (for example type Time:: and hit tab), reverse command search (control-R), and saved command history so when I exit and restart my command history is still there!

This entry was posted in Java, Ruby, Software Engineering. Bookmark the permalink.

3 Responses to Tab completion and history with irb and script/console

  1. Pingback: Ruby Brasil - » irb: histórico e tecla ‘tab’ para completar comandos