题
在〜/ .irbrc我有这些行:
require 'irb/ext/save-history'
#History configuration
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
可是当我运行irb
和命中向上箭头没有任何反应。还没有得到创建指定的IRB历史文件,并没有什么记录到它。
解决方案
我没有给你一个答案,为什么上面不工作,但我没有找到一个文件,/etc/irbrc
我的系统(OS X - 雪豹,红宝石1.8.7),它提供了一个工作,持久历史对我来说。所以两点建议:1)检查你的/ 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的开箱即用。毫无等/ irbrc,况且我有一个〜/ .irbrc。所以,hmmmm。
此人多放一点在他的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"
这是一个已知的错误具有可用的贴剂。最简单的解决方案是将保存覆盖-history.rb:
/usr/lib/ruby/1.8/irb/ext/save-history.rb
具有固定版本:
或做一气呵成:
wget -O /usr/lib/ruby/1.8/irb/ext/save-history.rb http://pastie.org/pastes/513500/download
检查,以确保您构建红宝石libreadline作为IRB历史似乎不是没有它的工作。
这也可能发生,如果你有额外的IRB的配置文件,如~/.irbrc
。如果是这样的情况下,从liwp的回答内容复制到额外的配置,它应该工作。
不隶属于 StackOverflow