summaryrefslogtreecommitdiff
path: root/lib/irb/ext/save-history.rb
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2019-07-15 07:51:57 +0900
committeraycabta <aycabta@gmail.com>2019-07-15 07:51:57 +0900
commit4b7a04a5b8a583e7e818155a73069a9e58a1a246 (patch)
tree665d666091113a5772b1c4a1d9a41aceaaf4d262 /lib/irb/ext/save-history.rb
parentd37da601289d13396b1e986b81d51b05bcfdddd5 (diff)
Support multiline irb_history
A history line ends with "\" to escape newline if it's a continuous line.
Diffstat (limited to 'lib/irb/ext/save-history.rb')
-rw-r--r--lib/irb/ext/save-history.rb20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/irb/ext/save-history.rb b/lib/irb/ext/save-history.rb
index 9aeb5dee0c..4ef6dbbd4e 100644
--- a/lib/irb/ext/save-history.rb
+++ b/lib/irb/ext/save-history.rb
@@ -73,7 +73,16 @@ module IRB
history_file = IRB.rc_file("_history") unless history_file
if File.exist?(history_file)
open(history_file) do |f|
- f.each {|l| history << l.chomp}
+ f.each { |l|
+ l = l.chomp
+ $stderr.puts l.inspect
+ if history.last&.end_with?("\\")
+ history.last.delete_suffix!("\\")
+ history.last << "\n" << l
+ else
+ history << l
+ end
+ }
end
end
end
@@ -98,7 +107,14 @@ module IRB
end
open(history_file, 'w', 0600 ) do |f|
- hist = history.to_a
+ hist = history.to_a.map { |l|
+ split_lines = l.split("\n")
+ if split_lines.size == 1
+ l
+ else
+ split_lines.join("\\\n")
+ end
+ }
f.puts(hist[-num..-1] || hist)
end
end