Sha256: df9bc0989acc3c8521dd8d59284ecdb403bfaf34072ff4009c367691602f0e9a

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'hairballs'

Hairballs.add_plugin(:irb_history, save_history: 1000, eval_history: 20, global_history_file: true) do |plugin|
  plugin.libraries %w(irb/ext/save-history)

  plugin.on_load do
    IRB.conf[:SAVE_HISTORY] = plugin.save_history
    IRB.conf[:EVAL_HISTORY] = plugin.eval_history

    unless plugin.global_history_file
      IRB.conf[:HISTORY_FILE] = "#{Dir.home}/.irb_history-#{Hairballs.project_name}"
    end

    Object.class_eval do
      # All of the ruby lines of code that have been executed.
      def history
        0.upto(Readline::HISTORY.size - 1) do |i|
          printf "%5d %s\n", i, Readline::HISTORY[i]
        end
      end

      # Execute one or many lines of Ruby from +history+.
      #
      # @param command_numbers [Fixnum,Range]
      def _!(command_numbers)
        cmds =
          if command_numbers.is_a? Range
            command_numbers.to_a.map { |i| Readline::HISTORY[i] }
          else
            [Readline::HISTORY[command_numbers]]
          end

        cmds.each { |cmd| send(cmd) }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hairballs-0.1.0 lib/hairballs/plugins/irb_history.rb