【发布时间】:2015-12-29 20:44:43
【问题描述】:
当我使用 pry 时,pry 的历史会不断覆盖我的 irb 历史,这很烦人。如果我使用 pry,我想查看 pry 历史,如果我使用 irb,我想查看 irb 历史。我的配置是否存在明显问题?
~/.irbrc 看起来像
IRB.conf[:AUTO_INDENT] = true
IRB.conf[:USE_READLINE] = true
IRB.conf[:LOAD_MODULES] = [] unless IRB.conf.key?(:LOAD_MODULES)
unless IRB.conf[:LOAD_MODULES].include?('irb/completion')
IRB.conf[:LOAD_MODULES] << 'irb/completion'
end
IRB.conf[:SAVE_HISTORY] = 1000
我的.pryrc 文件是空的,根据文档向我表明 pry 应该使用 .pry_history,这似乎正在发生。
/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
【问题讨论】:
-
如果在 .pryrc 文件中指定历史文件位置会发生什么(例如 here)?
-
我不确定这是否有意义,因为我确定 .pryrc 正在工作,我认为手头的真正问题是如何排除写入 .pry_history 的命令也被写入进入 .irb_history 文件
-
我实际上告诉 pry 明确地使用 .irb_history 并且这似乎运作良好,我可以从任何地方访问任何命令,这很好,所以我想我会坚持我得到的。
-
等等,什么?你是说问题是 pry 正在写 irb_history 和 pry_history (而且你不希望它破坏 irb_history)?但后来你告诉 pry 明确写信给 irb_history,现在你很高兴吗?
-
嗯,我不知道如何解释,但我认为整个 pry_history 正在覆盖 irb 历史并破坏 irb 历史,方法是设置 pry 显式写入 irb_history,现在整个 irb_history 不是t 被覆盖,所以基本上,我不知道,但我对我所拥有的更满意 :)