#89: view readline history in irb

Solved!
I wanted to view a log of all the lines I'd written in an IRB session, but didn't see a simple equivalent of bash's "history" command.

Readline::HISTORY

27
puts Readline::HISTORY.to_a

Comments

  1. Beautiful! Thanks!

    John on January 18, 2013, 08:57 PM UTC
  2. If you want to wrap it up, add this to your ~/.irbrc file (which gets loaded before your irb sessions):

    def irb_history( count = nil )
    hist = Readline::HISTORY.to_a

    if count
    len = hist.length
    from = len - count
    from = 0 if from < 0
    puts "len: #{len}, count: #{count}, from: #{from}, hist.class: #{hist.class}, hist.length: #{hist.length}"

    hist[from..-1]
    else
    hist
    end
    end

    I'm not sure how the formatting will work.

    Bryce on June 23, 2014, 09:02 PM UTC

Think you've got a better solution? Help 148c663fd665c53518538e093ce3c2ab_small kueda out by posting your solution