irb save-history not working

J

Julien Palmas

Hi,

I've set my .irbrc file with those line :

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

but my commands are not saved to .irb-save-history after exiting irb.

my entire .irbrc file can be found here : http://pastie.org/512760

I've dived a bit inside the save-history code and it seems that the
HistorySavingAbility.create_finalizer proc is never called.
The finalizer is set for the main_context @io object : an
IRB::ReadlineInputMethod object

I've googled a lot about irb history but all I could find was the irbrc
setup repeated again and again.

Has anyone had this kind of issue before ?
 
J

Joel VanderWerf

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

Fwiw, my .irbrc is missing that last line, but it does work, and saves
history to ~/.irb_history . Maybe there is a problem with explicitly
setting the history file?
 
J

Julien Palmas

Thx for your answer Joel, but I've tried with and without the line with
no success ...

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

Fwiw, my .irbrc is missing that last line, but it does work, and saves
history to ~/.irb_history . Maybe there is a problem with explicitly
setting the history file?
 
S

Stefan Rusterholz

Julien said:
Thx for your answer Joel, but I've tried with and without the line with
no success ...

I had the same problem. IRB uses (for whatever obscure reason)
finalizers to do the saving. Now finalizers are not guaranteed to be
run. And that's exactly what happens.
I wrote a fix for my save-history.rb, but I'm not sure how clean it is.
Anyway, for now it solves my problem and I'll share it with you. Hope it
helps you too:

http://pastie.org/513500

I put it into /opt/local/lib/ruby/site_ruby/1.8/irb/ext/save-history.rb,
you may have to change the /opt/local/lib part to where your ruby's lib
path is.

Regards
Stefan Rusterholz
 
J

Julien Palmas

Stefan said:
I had the same problem. IRB uses (for whatever obscure reason)
finalizers to do the saving. Now finalizers are not guaranteed to be
run. And that's exactly what happens.
I wrote a fix for my save-history.rb, but I'm not sure how clean it is.
Anyway, for now it solves my problem and I'll share it with you. Hope it
helps you too:

http://pastie.org/513500

I put it into /opt/local/lib/ruby/site_ruby/1.8/irb/ext/save-history.rb,
you may have to change the /opt/local/lib part to where your ruby's lib
path is.

Regards
Stefan Rusterholz

Hi Stefan,

Looks like this is a know bug, and you can find the ticket here
http://redmine.ruby-lang.org/issues/show/1556

The ticket was opened on June 2nd, but the bug appeared in the repo at
1.8.7-p83 (unreleased version), which is 5 month old. Hope it will be
fixed in the next release.

In the mean time, you can easily fix it yourself with the simple 2 lines
patch detailed at the end of the ticket.

Regards
Julien
 
S

Stefan Rusterholz

Julien said:
Hi Stefan,

Looks like this is a know bug, and you can find the ticket here
http://redmine.ruby-lang.org/issues/show/1556

The ticket was opened on June 2nd, but the bug appeared in the repo at
1.8.7-p83 (unreleased version), which is 5 month old. Hope it will be
fixed in the next release.

In the mean time, you can easily fix it yourself with the simple 2 lines
patch detailed at the end of the ticket.

Regards
Julien

Ah, good to know that they know. Sadly, I don't speak japanese so I
wouldn't find that entry.
However, my patch does almost exactly what the patch there does
(replaces the finalizer with an at_exit hook), but additionally adds the
ability to save only unique lines, via the IRB.conf[:HISTORY_NO_DUPS]
config option.

Regards
Stefan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top