Skip to content

Instantly share code, notes, and snippets.

@ravicious
Created November 6, 2009 21:21
Show Gist options
  • Save ravicious/228292 to your computer and use it in GitHub Desktop.
Save ravicious/228292 to your computer and use it in GitHub Desktop.
require "irb/completion"
require "rubygems"
# Modify the prompt so it looks nice and tidy. Taken from Programming Ruby 2.
IRB.conf[:IRB_RC] = proc do |conf|
conf.prompt_c = "?>"
conf.prompt_i = ">> "
conf.prompt_n = ">> "
conf.prompt_s = nil
conf.prompt_mode = :SIMPLE
conf.return_format = "=> %s\n"
end
HISTFILE = "~/.irb_history"
MAXHISTSIZE = 100
begin
if defined? Readline::HISTORY
histfile = File::expand_path( HISTFILE )
if File::exists?( histfile )
lines = IO::readlines( histfile ).collect {|line| line.chomp}
puts "Read %d saved history commands from %s." %
[ lines.nitems, histfile ] if $DEBUG || $VERBOSE
Readline::HISTORY.push( *lines )
else
puts "History file '%s' was empty or non-existant." %
histfile if $DEBUG || $VERBOSE
end
Kernel::at_exit {
lines = Readline::HISTORY.to_a.reverse.uniq.reverse
lines = lines[ -MAXHISTSIZE, MAXHISTSIZE ] if lines.nitems > MAXHISTSIZE
$stderr.puts "Saving %d history lines to %s." %
[ lines.length, histfile ] if $VERBOSE || $DEBUG
File::open( histfile, File::WRONLY|File::CREAT|File::TRUNC ) {|ofh|
lines.each {|line| ofh.puts line }
}
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment