irb历史不起作用

在〜/ .irbrc我有这些线:

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

然而,当我运行irb并击中向上箭头时没有任何反应。 还没有创建指定的irb历史文件,也没有记录任何内容。

我没有给你答案为什么以上不起作用,但我确实在我的系统(OS X – Snow Leopard,Ruby 1.8.7)上找到了一个文件/etc/irbrc ,它提供了一个可行的,持久的我的历史。 所以有两条建议:i)检查你的/ etc / irbrc(或等效的)以确保其中没有任何可能会干扰你的设置的东西,以及ii)尝试下面的设置,看看你是否可以得到历史那样工作。

 # 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 

irb历史适用于Debian Linux开箱即用。 没有etc / irbrc,也没有〜/ .irbrc。 所以,嗯。

这个人比你做的更多。 你认为ARGV.concat可能是缺失的部分吗?

 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" 

这是一个可用补丁的已知错误。 最简单的解决方案是覆盖save-history.rb:

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

固定版本:

http://pastie.org/513500

或者一气呵成:

 wget -O /usr/lib/ruby/1.8/irb/ext/save-history.rb http://pastie.org/pastes/513500/download 

检查以确保使用libreadline构建ruby,因为如果没有它,irb历史似乎不起作用。

如果您有额外的irb配置文件,例如~/.irbrc ,也可能发生这种情况。 如果是这种情况,请将liwp的答案中的内容复制到额外的配置中,它应该有效。