Irb history not working

in ~ / .irbrc I have the following lines:

require 'irb/ext/save-history' #History configuration IRB.conf[:SAVE_HISTORY] = 100 IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history" 

and yet when I run irb and irb up arrow nothing happens. also the specified irb history file is not created and nothing is written to it.

+12
ruby irb
Jan 14 '10 at 17:01
source share
5 answers

I have no answer for you why this does not work, but I found the file /etc/irbrc on my system (OS X - Snow Leopard, Ruby 1.8.7), which provides a consistent history for me. So, two tips: i) check / etc / irbrc (or the equivalent) to make sure there is nothing to interfere with your settings, and ii) try the settings below to see if you can get the story working So.

 # Some default enhancements/settings for IRB, based on # http://wiki.rubygarden.org/Ruby/page/show/Irb/TipsAndTricks unless defined? ETC_IRBRC_LOADED # Require RubyGems by default. require 'rubygems' # Activate auto-completion. require 'irb/completion' # Use the simple prompt if possible. IRB.conf[:PROMPT_MODE] = :SIMPLE if IRB.conf[:PROMPT_MODE] == :DEFAULT # Setup permanent history. HISTFILE = "~/.irb_history" MAXHISTSIZE = 100 begin histfile = File::expand_path(HISTFILE) if File::exists?(histfile) lines = IO::readlines(histfile).collect { |line| line.chomp } puts "Read #{lines.nitems} saved history commands from '#{histfile}'." if $VERBOSE Readline::HISTORY.push(*lines) else puts "History file '#{histfile}' was empty or non-existant." if $VERBOSE end Kernel::at_exit do lines = Readline::HISTORY.to_a.reverse.uniq.reverse lines = lines[-MAXHISTSIZE, MAXHISTSIZE] if lines.nitems > MAXHISTSIZE puts "Saving #{lines.length} history lines to '#{histfile}'." if $VERBOSE File::open(histfile, File::WRONLY|File::CREAT|File::TRUNC) { |io| io.puts lines.join("\n") } end rescue => e puts "Error when configuring permanent history: #{e}" if $VERBOSE end ETC_IRBRC_LOADED=true end 
+11
Jan 14 '10 at 17:50
source share

The history of irb works in Debian Linux out of the box. There is no etc / irbrc, and I don't have ~ / .irbrc. So hmmmm.

This person added a little more of his irbrc than you. Do you think ARGV.concat might be the missing piece?

 require 'irb/completion' require 'irb/ext/save-history' ARGV.concat [ "--readline", "--prompt-mode", "simple" ] IRB.conf[:SAVE_HISTORY] = 100 IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history" 
+17
Jan 14
source share

This is a known bug with an available patch. The easiest solution is to overwrite save-history.rb:

/usr/lib/ruby/1.8/irb/ext/save-history.rb

with fixed version:

http://pastie.org/513500

or do it in one go:

 wget -O /usr/lib/ruby/1.8/irb/ext/save-history.rb http://pastie.org/pastes/513500/download 
+1
Feb 06 '10 at 13:35
source share

Make sure you create ruby ​​with libreadline, as the irb story doesn't seem to work without it.

0
Jan 03 '12 at 17:44
source share

This can also happen if you have an additional irb configuration file, for example. ~/.irbrc . If so, copy the content from the liwp answer to the additional configuration and it should work.

0
Aug 05 '16 at 10:58 on
source share



All Articles