Class: ZshHistoryParser

Inherits:
HistoryParserInterface show all
Defined in:
lib/parser/zsh_history_parser.rb

Overview

Parse the ZSH history file

Instance Method Summary collapse

Instance Method Details

#commandsObject



17
18
19
20
21
22
23
24
25
# File 'lib/parser/zsh_history_parser.rb', line 17

def commands
  commands = []
  File.open(history_file, 'r') do |f|
    f.each_line do |line|
      commands.push(parse_command(line))
    end
  end
  commands
end

#history_fileObject



27
28
29
# File 'lib/parser/zsh_history_parser.rb', line 27

def history_file
  File.expand_path(ZSH_HISTORY_FILE_PATH)
end

#parse_command(history_line_entry) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/parser/zsh_history_parser.rb', line 7

def parse_command(history_line_entry)
  # get everything on the left hand side of the ';'
  # and join the content. We want to join the content
  # in the case that the command itself has a ';' e.g.
  # : 1650408552:0;git status; git clear
  split_history = history_line_entry.split(';')
  command_part = split_history.drop(1)
  command_part.join(';').strip
end