代码之家  ›  专栏  ›  技术社区  ›  quinn

irb历史记录不起作用

  •  14
  • quinn  · 技术社区  · 16 年前

    在~/.irbrc中,我有以下几行:

    require 'irb/ext/save-history'
    #History configuration
    IRB.conf[:SAVE_HISTORY] = 100
    IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"
    

    irb 按向上箭头,什么也没发生。此外,未创建指定的irb历史文件,且未记录任何内容。

    5 回复  |  直到 16 年前
        1
  •  11
  •   liwp    16 年前

    我不知道为什么上面的方法不起作用,但我找到了一个文件, /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
    
        2
  •  20
  •   Wayne Conrad    16 年前

    This person

    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" 
    
        3
  •  1
  •   Mike McKay    16 年前

    这是一个已知的bug,有可用的补丁。最简单的解决方案是覆盖save-history.rb:

    /usr/lib/ruby/1.8/irb/ext/save-history.rb

    对于固定版本:

    http://pastie.org/513500

    或者一次性完成:

    wget -O /usr/lib/ruby/1.8/irb/ext/save-history.rb http://pastie.org/pastes/513500/download
    
        4
  •  0
  •   jwood    14 年前

    检查以确保您使用libreadline构建了ruby,因为没有它,irb历史记录似乎无法工作。

        5
  •  0
  •   medik    10 年前

    ~/.irbrc . 如果是这种情况,将liwp的答案中的内容复制到额外的配置中,它应该可以工作。

        6
  •  0
  •   Rob Geraghty    5 年前

    我在Ubuntu20.04上遇到了同样的问题,并通过运行以下命令进行了修复:

    gem install irb
    
    推荐文章