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. eric says:

    amazing… after 30 or so articles on how to compile readline into ruby, this fixed my issue with script/console not loading readline.

    Thank you

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

  3. fabrice says:

    I use ruby on rails on linux SUSE 10.1 and script/console failed to launch with an error loading readline. With your file, all is OK now.
    Thank you

Comments are closed.