From: Thomas Uehlinger Date: 2004-02-07T03:15:37+09:00 Subject: [PATCH] Persistent IRB history This is a multi-part message in MIME format. --Multipart=_Fri__6_Feb_2004_19_15_21_+0100_JbBdZewNe.APic.Q Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Hi all I found persistent Readline history (i.e. saved to a hidden file in the users home directory) a pretty useful feature in other applicatons. So here is a patch for IRB so the history gets automatically saved to ~/.irb_history and will be loaded next time IRB is used. Comments? -- Thomas Uehlinger --Multipart=_Fri__6_Feb_2004_19_15_21_+0100_JbBdZewNe.APic.Q Content-Type: text/x-diff; name="input-method.rb.patch" Content-Disposition: attachment; filename="input-method.rb.patch" Content-Transfer-Encoding: 7bit --- input-method_old.rb 2004-02-06 19:06:58.920287816 +0100 +++ input-method.rb 2004-02-06 19:04:50.228851888 +0100 @@ -85,12 +85,33 @@ require "readline" class ReadlineInputMethod < InputMethod include Readline + + def ReadlineInputMethod.create_finalizer(hist) + proc {|id| + open(File.join(ENV["HOME"], '.irb_history'), 'w' ) {|f| + i = 0 + while (l = hist.pop and i < 50) + f.puts(l) + i += 1 + end + } + } + end + def initialize super @line_no = 0 @line = [] @eof = false + + begin + lines = File.readlines(File.join(ENV["HOME"], '.irb_history')) + lines.reverse.each {|l| HISTORY.push << l.chomp } + HISTORY.pop + rescue + end + ObjectSpace.define_finalizer(self, ReadlineInputMethod.create_finalizer(HISTORY)) end def gets --Multipart=_Fri__6_Feb_2004_19_15_21_+0100_JbBdZewNe.APic.Q--