为什么撬历史会阻止历史?

当我使用撬时,撬的历史会一直覆盖我的irb历史并且非常烦人。 如果我使用撬,我想看到撬的历史,如果我使用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文件是空的,基于docs告诉我, .pry_history应该使用.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 

为什么会出现问题

Pry和IRB都将他们的历史写入Readline::HISTORY 。 当您从IRB(或rails console )输入Pry时,您的所有IRB历史记录已在Readline::HISTORY 。 然后Pry加载它的历史。 当您退出Pry Readline::HISTORY没有改变,所以你最终回到IRB,所有Pry的历史都附加到IRB的历史记录中。 最后,当您退出IRB时,它会将包含Pry的历史记录写入IRB的历史文件,从而破坏它。

目前的问题状态

我做了一些搜索,发现这是Pry的一个已知问题 。 我对这个问题也很感兴趣所以我设法制定了一个等待拉取请求审查的解决方案。

解决方法直到合并

如果您想在它合并之前尝试一下,您可以从我在Pry的分支上创建的分支中获取该版本。 您可以在分支save_irb_history_and_replace_on_close下的https://github.com/agrberg/pry上找到它。 如果你使用bundler你需要做的就是添加或更新你的pry行:

 gem 'pry', git: 'git@github.com:agrberg/pry.git', branch: 'save_irb_history_and_replace_on_close'