class Gitlab::Shell::History
Constants
- DEFAULT_FILE_PATH
- DEFAULT_HISTFILESIZE
Public Class Methods
new(options={})
click to toggle source
# File lib/gitlab/shell_history.rb, line 6 def initialize(options={}) @file_path = options[:file_path] || DEFAULT_FILE_PATH Readline::HISTORY.clear end
Public Instance Methods
lines()
click to toggle source
# File lib/gitlab/shell_history.rb, line 24 def lines Readline::HISTORY.to_a.last(max_lines) end
load()
click to toggle source
# File lib/gitlab/shell_history.rb, line 11 def load read_from_file { |line| Readline::HISTORY << line.chomp } end
push(line)
click to toggle source
# File lib/gitlab/shell_history.rb, line 19 def push(line) Readline::HISTORY << line end
Also aliased as: <<
save()
click to toggle source
# File lib/gitlab/shell_history.rb, line 15 def save lines.each { |line| history_file.puts line if history_file } end
Private Instance Methods
history_file()
click to toggle source
# File lib/gitlab/shell_history.rb, line 30 def history_file if defined?(@history_file) @history_file else @history_file = File.open(history_file_path, 'w', 0600).tap do |file| file.sync = true end end rescue Errno::EACCES warn 'History not saved; unable to open your history file for writing.' @history_file = false end
history_file_path()
click to toggle source
# File lib/gitlab/shell_history.rb, line 43 def history_file_path File.expand_path(@file_path) end
max_lines()
click to toggle source
# File lib/gitlab/shell_history.rb, line 55 def max_lines (ENV['GITLAB_HISTFILESIZE'] || DEFAULT_HISTFILESIZE).to_i end
read_from_file() { |line| ... }
click to toggle source
# File lib/gitlab/shell_history.rb, line 47 def read_from_file path = history_file_path File.foreach(path) { |line| yield(line) } if File.exist?(path) rescue => error warn "History file not loaded: #{error.message}" end