Sha256: 3bff73ae710f5b2c56230fe8df6f98aa0e81ff43cee5c9452f2c4fc65c2173fc
Contents?: true
Size: 1.5 KB
Versions: 4
Compression:
Stored size: 1.5 KB
Contents
require 'rib' require 'fileutils' module Rib::History extend Rib::Plugin Shell.use(self) # --------------- Rib API --------------- def before_loop return super if History.disabled? history_file history_size FileUtils.mkdir_p(File.dirname(history_file_path)) read_history Rib.say("History read from: #{history_file_path}") if $VERBOSE super end def after_loop return super if History.disabled? write_history Rib.say("History wrote to: #{history_file_path}") if $VERBOSE super end def get_input return super if History.disabled? (history << super).last end # --------------- Plugin API --------------- # The history data def history; config[:history] ||= []; end # Read config[:history_file] into #history, handled in history_file plugin def read_history return super if History.disabled? File.exist?(history_file_path) && history.empty? && File.readlines(history_file_path).each{ |e| history << e.chomp } end # Write #history into config[:history_file], handled in history_file plugin def write_history return super if History.disabled? history_text = "#{history.to_a.last(history_size).join("\n")}\n" File.write(history_file_path, history_text) end private def history_file config[:history_file] ||= File.join(Rib.home, 'history.rb') end def history_file_path config[:history_file_path] ||= File.expand_path(history_file) end def history_size config[:history_size] ||= 500 end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rib-1.5.1 | lib/rib/core/history.rb |
rib-1.5.0 | lib/rib/core/history.rb |
rib-1.4.0 | lib/rib/core/history.rb |
rib-1.3.1 | lib/rib/core/history.rb |