Class: HammerCLI::ShellHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/hammer_cli/shell.rb

Instance Method Summary collapse

Constructor Details

#initialize(history_file_path) ⇒ ShellHistory

Returns a new instance of ShellHistory.



42
43
44
45
# File 'lib/hammer_cli/shell.rb', line 42

def initialize(history_file_path)
  @file_path = history_file_path
  load
end

Instance Method Details

#ingonred_commandsObject



57
58
59
# File 'lib/hammer_cli/shell.rb', line 57

def ingonred_commands
  ["exit"]
end

#push(line) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/hammer_cli/shell.rb', line 47

def push(line)
  line.strip!
  return if line.empty? or ingonred_commands.include?(line)

  Readline::HISTORY.push(line)
  File.open(file_path, "a") do |f|
    f.puts(line)
  end
end