zsh だと複数行の履歴を一度に表示する機能があります。例えば、いま手元でCtrl-r で履歴 ./ruby を検索すると以下のように履歴に表示されました。
$ ./ruby -ve '
[1, 2].each{|v|
Thread.start{
p v
}
}
'
irb でも
irb(main):001:0> class Foo irb(main):002:1> def foo irb(main):003:2> "foo" irb(main):004:2> end irb(main):005:1> end
なんて入力した時は、履歴を検索した時に
irb(main):006:0> class Foo
def foo
"foo"
end
end
と表示してほしいですよね。以下のようなパッチで実現できます。
Index: irb.rb
===================================================================
RCS file: /src/ruby/lib/irb.rb,v
retrieving revision 1.7
diff -u -1 -r1.7 irb.rb
--- irb.rb 10 Jun 2003 05:22:16 -0000 1.7
+++ irb.rb 19 Feb 2005 03:25:57 -0000
@@ -97,2 +97,3 @@
@scanner.exception_on_syntax_error = false
+ @hist_buf = nil
end
@@ -125,2 +126,8 @@
end
+ if indent == 0
+ if @hist_buf and @hist_buf != Readline::HISTORY[-1]
+ Readline::HISTORY.push(@hist_buf)
+ end
+ @hist_buf = nil
+ end
end
@@ -131,2 +138,8 @@
print l if @context.verbose?
+ if @hist_buf
+ @hist_buf = @hist_buf + "\n" +
+ ' ' * @context.io.prompt.size + Readline::HISTORY.pop
+ else
+ @hist_buf = Readline::HISTORY.pop
+ end
else
IRB.conf[:SAVE_HISTORY] を true に設定してファイルに履歴を保存するようにしている場合は、以下のようなパッチも必要。
Index: input-method.rb
===================================================================
RCS file: /src/ruby/lib/irb/input-method.rb,v
retrieving revision 1.5
diff -u -1 -r1.5 input-method.rb
--- input-method.rb 7 Feb 2004 10:56:16 -0000 1.5
+++ input-method.rb 19 Feb 2005 03:02:11 -0000
@@ -96,3 +96,3 @@
open(file, 'w' ) do |f|
- hist = hist.to_a
+ hist = hist.to_a.map{|s| s.gsub(/(?!\Z)$/, '\\')}
f.puts(hist[-num..-1] || hist)
@@ -111,3 +111,14 @@
- loader = proc {|f| f.each {|l| HISTORY << l.chomp}}
+ loader = proc {|f|
+ buf = ''
+ f.each {|l|
+ if /\\\n/ =~ l
+ buf << l.sub(/\\\n/, "\n")
+ else
+ buf << l
+ HISTORY << buf.chomp
+ buf = ''
+ end
+ }
+ }
if hist = IRB.conf[:HISTORY_FILE]
最近のコメント