Reputation: 119
I use the following .irbrc
with irb under ruby 2.3.5 on FreeBSD:
require 'irb/completion'
require 'irb/ext/save-history'
IRB.conf[:SAVE_HISTORY] = 10000
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:HISTORY_FILE] = "/home/ebot/.irb_history"
When I exit irb, the history gets saved to /home/ebot/.irb_history
as expected. However, when I start another irb session, the Readline::History
list is empty and pressing the <up>
key has no effect.
I put the following code into my .irbrc
:
if File.exist?(IRB.conf[:HISTORY_FILE]) then
prev = ''
File.open(IRB.conf[:HISTORY_FILE]).each do |line|
line.chomp!
if line.length > 0 then
if line != prev then
puts "pushing hist <#{line}>"
Readline::HISTORY.push(line)
prev = line
end
end
end
end
When I execute irb with this, I see several lines of the above output, but still, history is empty:
% irb
irb(main):001:0> 1+1
=> 2
irb(main):002:0> 3+3
=> 6
irb(main):003:0> ^D
% cat .irb_history
1+1
3+3
% irb
pushing hist <1+1>
pushing hist <3+3>
irb(main):001:0> Readline::HISTORY.to_a
=> ["Readline::HISTORY.to_a"]
So, irb seems to reset/empty this list after executing .irbrc
.
How can I fix this?
Upvotes: 2
Views: 487
Reputation: 119
On FreeBSD, ruby needs to be compiled with readline support, not libedit.
Upvotes: 3