Tôi không có câu trả lời cho bạn tại sao những điều trên không hiệu quả, nhưng tôi đã tìm thấy tệp, /etc/irbrc
trên hệ thống của mình (OS X - Snow Leopard, Ruby 1.8.7) lịch sử liên tục cho tôi. Vì vậy, hai lời khuyên: i) kiểm tra/etc/irbrc (hoặc tương đương) để đảm bảo rằng không có bất kỳ thứ gì trong đó có thể ảnh hưởng đến cài đặt của bạn và ii) thử các cài đặt bên dưới để xem bạn có thể nhận được không lịch sử làm việc theo cách đó.
# 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
Bạn đang sử dụng nền tảng nào? Tôi khá chắc chắn rằng cài đặt mặc định OS X không có hỗ trợ readline được xây dựng do vấn đề cấp phép. –
Những gì bạn có ở đó xuất hiện để làm việc cho tôi trên doze, ngoại trừ việc tôi phải nhấn hai mũi tên lên vì một lý do nào đó. – rogerdpack
Giải pháp này làm việc cho tôi: http://stackoverflow.com/questions/1752461/history-not-saving –