Class: Appydave::Tools::ZshHistory::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/appydave/tools/zsh_history/parser.rb

Overview

Parses ZSH history file, handling multi-line commands with \ continuations

Constant Summary collapse

HISTORY_LINE_PATTERN =

ZSH history line format: : timestamp:duration;command

/^: (\d+):\d+;(.*)$/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path = nil) ⇒ Parser

Returns a new instance of Parser.



13
14
15
16
# File 'lib/appydave/tools/zsh_history/parser.rb', line 13

def initialize(file_path = nil)
  @file_path = file_path || default_history_path
  @commands = []
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



11
12
13
# File 'lib/appydave/tools/zsh_history/parser.rb', line 11

def commands
  @commands
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



11
12
13
# File 'lib/appydave/tools/zsh_history/parser.rb', line 11

def file_path
  @file_path
end

Instance Method Details

#parseObject



18
19
20
21
22
23
# File 'lib/appydave/tools/zsh_history/parser.rb', line 18

def parse
  return [] unless File.exist?(file_path)

  lines = read_file
  @commands = parse_lines(lines)
end