Posted By

ctran on 09/07/06


Tagged

irbrc


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


my irbrc


 / Published in: Ruby
 

Put this in your .irbrc to turn on autocompletion and remember the last 100 commands

  1. #require 'rubygems'
  2. #require 'wirble'
  3. #Wirble.init
  4. #Wirble.colorize
  5.  
  6. IRB.conf[:AUTO_INDENT] = true
  7. IRB.conf[:USE_READLINE] = true
  8. IRB.conf[:LOAD_MODULES] = [] unless IRB.conf.key?(:LOAD_MODULES)
  9. unless IRB.conf[:LOAD_MODULES].include?('irb/completion')
  10. IRB.conf[:LOAD_MODULES] << 'irb/completion'
  11. end
  12.  
  13. HISTFILE = "~/.irb_history"
  14. MAXHISTSIZE = 100
  15.  
  16. begin
  17. if defined? Readline::HISTORY
  18. histfile = File::expand_path( HISTFILE )
  19. if File::exists?( histfile )
  20. lines = IO::readlines( histfile ).collect {|line| line.chomp}
  21. puts "Read %d saved history commands from %s." %
  22. [ lines.nitems, histfile ] if $DEBUG || $VERBOSE
  23. Readline::HISTORY.push( *lines )
  24. else
  25. puts "History file '%s' was empty or non-existant." %
  26. histfile if $DEBUG || $VERBOSE
  27. end
  28.  
  29. Kernel::at_exit {
  30. lines = Readline::HISTORY.to_a.reverse.uniq.reverse
  31. lines = lines[ -MAXHISTSIZE, MAXHISTSIZE ] if lines.nitems > MAXHISTSIZE
  32. $stderr.puts "Saving %d history lines to %s." %
  33. [ lines.length, histfile ] if $VERBOSE || $DEBUG
  34. File::open( histfile, File::WRONLY|File::CREAT|File::TRUNC ) {|ofh|
  35. lines.each {|line| ofh.puts line }
  36. }
  37. }
  38. end
  39. end
  40.  
  41. puts '.irbc completed'

Report this snippet  

You need to login to post a comment.