سؤال

في ~/.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 - Snow Leopard ، Ruby 1.8.7) الذي يوفر تاريخًا ثابتًا ومستمرًا بالنسبة لي. لذا فإن هناك نصيحة: التاريخ يعمل بهذه الطريقة.

# 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 خارج الصندوق. لا يوجد ETC/IRBRC ، وليس لدي ~/.irbrc. لذلك ، هممم.

هذا الشخص ضع أكثر قليلاً في 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" 

هذا خطأ معروف مع تصحيح متاح. أسهل حل هو الكتابة فوق الحفظ- تاريخ: 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

تحقق للتأكد من أنك بنيت Ruby مع Libreadline حيث يبدو أن تاريخ IRB لا يعمل بدونه.

قد يحدث هذا أيضًا إذا كان لديك ملف تكوين IRB إضافي ، على سبيل المثال ~/.irbrc. إذا كان هذا هو الحال ، فقم بنسخ المحتوى من إجابة LIWP على التكوين الإضافي ويجب أن يعمل.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top