1# Some default enhancements/settings for IRB, based on 2# http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks 3 4unless defined? ETC_IRBRC_LOADED 5 6 # Require RubyGems by default. 7 require 'rubygems' 8 9 # Activate auto-completion. 10 require 'irb/completion' 11 12 # Use the simple prompt if possible. 13 IRB.conf[:PROMPT_MODE] = :SIMPLE if IRB.conf[:PROMPT_MODE] == :DEFAULT 14 15 # Setup permanent history. 16 HISTFILE = "~/.irb_history" 17 MAXHISTSIZE = 100 18 begin 19 histfile = File::expand_path(HISTFILE) 20 if File::exists?(histfile) 21 lines = IO::readlines(histfile).collect { |line| line.chomp } 22 puts "Read #{lines.nitems} saved history commands from '#{histfile}'." if $VERBOSE 23 Readline::HISTORY.push(*lines) 24 else 25 puts "History file '#{histfile}' was empty or non-existant." if $VERBOSE 26 end 27 Kernel::at_exit do 28 lines = Readline::HISTORY.to_a.reverse.uniq.reverse 29 lines = lines[-MAXHISTSIZE, MAXHISTSIZE] if lines.nitems > MAXHISTSIZE 30 puts "Saving #{lines.length} history lines to '#{histfile}'." if $VERBOSE 31 File::open(histfile, File::WRONLY|File::CREAT|File::TRUNC) { |io| io.puts lines.join("\n") } 32 end 33 rescue => e 34 puts "Error when configuring permanent history: #{e}" if $VERBOSE 35 end 36 37 ETC_IRBRC_LOADED=true 38end 39