2
votes

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?

1
Use pry instead of IRB, since it is much better in general and supports everything you might need, including history, out of the box. - Aleksei Matiushkin
Great, I've got the same problem with pry as well :( The only difference is, that .pry_history contains all commands ever entered. But <up> still has no effect. Looks like an readline issue? - Tom
Try Ctrl+R and start typing the command that is presented in the history. Does it appear in the prompt line? - Aleksei Matiushkin
Nope. Seems to be an issue with ruby+readline. - Tom
Ok, my fault. I recompiled ruby. In the options menu I had libedit enabled instead of readline. I changed this, rebuilt, and now it works. - Tom

1 Answers

3
votes

On FreeBSD, ruby needs to be compiled with readline support, not libedit.