在〜/ .irbrc我有这些行:
require 'irb/ext/save-history' #History configuration IRB.conf[:SAVE_HISTORY] = 100 IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
然而当我跑步irb
并击中向上箭头时没有任何反应.也没有创建指定的irb历史文件,也没有记录任何内容.
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"
我没有给你答案为什么上面的方法不起作用,但我确实/etc/irbrc
在我的系统上找到了一个文件(OS X - Snow Leopard,Ruby 1.8.7),它为我提供了一个有效的,持续的历史记录.所以有两条建议: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