首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >irb历史不起作用

irb历史不起作用
EN

Stack Overflow用户
提问于 2010-01-14 17:01:00
回答 6查看 21.3K关注 0票数 15

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

代码语言:javascript
复制
require 'irb/ext/save-history'
#History configuration
IRB.conf[:SAVE_HISTORY] = 100
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.irb-save-history"

然而,当我运行irb并点击向上箭头时,什么都不会发生。此外,指定的irb历史文件不会被创建,也不会被记录到其中。

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2010-01-14 17:50:01

我没有一个答案,为什么上面的不工作,但我确实找到了一个文件,/etc/irbrc在我的系统(OS雪豹,Ruby1.8.7),为我提供了一个工作的,持久的历史。因此,有两条建议:一)检查你的/etc/irbrc (或等效的),以确保里面没有任何东西可能会干扰你的设置;二)尝试下面的设置,看看你是否可以让历史以这种方式工作。

代码语言:javascript
复制
# 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
票数 11
EN

Stack Overflow用户

发布于 2010-01-14 17:56:25

irb历史可以直接在Debian中运行。没有etc/irbrc,我也没有/.irbrc。那么,嗯。

这个人比你投入了更多的精力。你认为ARGV.concat可能是缺失的部分吗?

代码语言:javascript
复制
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" 
票数 20
EN

Stack Overflow用户

发布于 2010-02-06 13:35:37

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

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

有固定版本:

http://pastie.org/513500

或者一蹴而就:

代码语言:javascript
复制
wget -O /usr/lib/ruby/1.8/irb/ext/save-history.rb http://pastie.org/pastes/513500/download
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2065923

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档