在~/..irbrc中,我有以下几行:
require 'irb/ext/save-history'
#History configuration
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"然而,当我运行irb并点击向上箭头时,什么都不会发生。此外,指定的irb历史文件不会被创建,也不会被记录到其中。
发布于 2010-01-14 17:50:01
我没有一个答案,为什么上面的不工作,但我确实找到了一个文件,/etc/irbrc在我的系统(OS雪豹,Ruby1.8.7),为我提供了一个工作的,持久的历史。因此,有两条建议:一)检查你的/etc/irbrc (或等效的),以确保里面没有任何东西可能会干扰你的设置;二)尝试下面的设置,看看你是否可以让历史以这种方式工作。
# 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发布于 2010-01-14 17:56:25
irb历史可以直接在Debian中运行。没有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" 发布于 2010-02-06 13:35:37
这是一个已知的bug,有一个可用的修补程序。最简单的解决方案是覆盖save-history.rb. is:
/usr/lib/ruby/1.8/irb/ext/save-history.rb y.rb
有固定版本:
http://pastie.org/513500
或者一蹴而就:
wget -O /usr/lib/ruby/1.8/irb/ext/save-history.rb http://pastie.org/pastes/513500/downloadhttps://stackoverflow.com/questions/2065923
复制相似问题