Skip to content

Instantly share code, notes, and snippets.

@pch pch/gist:577258
Created Sep 13, 2010

Embed
What would you like to do?
# source: http://www.enriquedelgado.com/articles/2007/04/25/interactive-ruby-console-tip-remember-the-last-x-commands-even-after-logging-out
# file: .irbrc
IRB.conf[:PROMPT_MODE] = :SIMPLE
require 'irb/completion'
IRB.conf[:AUTO_INDENT] = true
# Session History
HISTFILE = "~/.irb.hist" unless defined? HISTFILE
MAXHISTSIZE = 100 unless defined? MAXHISTSIZE
begin
if defined? Readline::HISTORY
histfile = File::expand_path(HISTFILE)
if File::exists?(histfile)
lines = IO::readlines(histfile).collect { |line| line.chomp }
Readline::HISTORY.push(*lines)
end
Kernel::at_exit {
lines = Readline::HISTORY.to_a.reverse.uniq.reverse
lines = lines[-MAXHISTSIZE, MAXHISTSIZE] if lines.nitems > MAXHISTSIZE
File::open(histfile, File::WRONLY | File::CREAT | File::TRUNC) {|f| lines.each {|line| f.puts line }}
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.