class Gitlab::Shell::History
Constants
- DEFAULT_FILE_PATH
- DEFAULT_HISTFILESIZE
Public Class Methods
Source
# File lib/gitlab/shell_history.rb, line 8 def initialize(options = {}) @file_path = options[:file_path] || DEFAULT_FILE_PATH Readline::HISTORY.clear end
Public Instance Methods
Source
# File lib/gitlab/shell_history.rb, line 26 def lines Readline::HISTORY.to_a.last(max_lines) end
Source
# File lib/gitlab/shell_history.rb, line 13 def load read_from_file { |line| Readline::HISTORY << line.chomp } end
Source
# File lib/gitlab/shell_history.rb, line 21 def push(line) Readline::HISTORY << line end
Also aliased as: <<
Source
# File lib/gitlab/shell_history.rb, line 17 def save lines.each { |line| history_file&.puts line } end
Private Instance Methods
Source
# File lib/gitlab/shell_history.rb, line 32 def history_file @history_file ||= File.open(history_file_path, 'w', 0o600).tap do |file| file.sync = true end rescue Errno::EACCES warn 'History not saved; unable to open your history file for writing.' @history_file = false end
Source
# File lib/gitlab/shell_history.rb, line 41 def history_file_path File.expand_path(@file_path) end
Source
# File lib/gitlab/shell_history.rb, line 53 def max_lines (ENV['GITLAB_HISTFILESIZE'] || DEFAULT_HISTFILESIZE).to_i end
Source
# File lib/gitlab/shell_history.rb, line 45 def read_from_file(&block) path = history_file_path File.foreach(path, &block) if File.exist?(path) rescue StandardError => e warn "History file not loaded: #{e.message}" end