Sha256: be8039158597bdfb477cb220a75c3979c1db16050bc0cf1a6844d039ee756b0d
Contents?: true
Size: 873 Bytes
Versions: 1
Compression:
Stored size: 873 Bytes
Contents
require 'rib' require 'fileutils' module Rib::HistoryFile include Rib::Plugin Shell.use(self) def before_loop return super if HistoryFile.disabled? config[:history_file] ||= '~/.config/rib/history.rb' config[:history_size] ||= 500 FileUtils.mkdir_p(File.dirname(history_file)) super end def get_input return super if HistoryFile.disabled? (history << super).last end def read_history return super if HistoryFile.disabled? File.exist?(history_file) && history.empty? && File.readlines(history_file).each{ |e| history << e.chomp } end def write_history return super if HistoryFile.disabled? File.open(history_file, 'w'){ |f| f.puts(history.to_a.last(config[:history_size]).join("\n")) } end private def history_file @history_file ||= File.expand_path(config[:history_file]) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rib-0.1.0 | lib/rib/core/history_file.rb |