Sha256: f04ca4642e6453b01a2ba424cc1dd95f0aa7bebd7962d32f8d8434e5f42f2973

Contents?: true

Size: 994 Bytes

Versions: 5

Compression:

Stored size: 994 Bytes

Contents

require 'rib/core/history' # dependency

module Rib; module SqueezeHistory
  extend Plugin
  Shell.use(self)

  # --------------- Rib API ---------------

  # squeeze history in memory too
  def loop_once
    return super if SqueezeHistory.disabled?
    begin
      input, last_input = history[-1], history[-2]
    rescue IndexError # EditLine is really broken, to_a is needed for it
      array = history.to_a
      input, last_input = array[-1], array[-2]
    end
    history.pop if input.to_s.strip == '' ||
                  (history.size > 1 && input == last_input)
    super
  end

  # --------------- Plugin API ---------------

  # write squeezed history
  def write_history
    return super if SqueezeHistory.disabled?
    config[:history] = squeezed_history
    super
  end



  private
  def squeezed_history
    history.to_a.inject([]){ |result, item|
      if result.last == item || item.strip == ''
        result
      else
        result << item
      end
    }
  end
end; end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rib-1.6.1 lib/rib/core/squeeze_history.rb
rib-1.6.0 lib/rib/core/squeeze_history.rb
rib-1.5.4 lib/rib/core/squeeze_history.rb
rib-1.5.3 lib/rib/core/squeeze_history.rb
rib-1.5.2 lib/rib/core/squeeze_history.rb