Skip to content

Instantly share code, notes, and snippets.

@pch
Created September 13, 2010 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pch/577258 to your computer and use it in GitHub Desktop.
Save pch/577258 to your computer and use it in GitHub Desktop.
# 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