Class: Agen::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/agen/runner.rb

Constant Summary collapse

CONFIG_FILE =
"#{Dir.home}/.agen"
DEFAULT_HISTFILE =
ZshOptions::HISTFILE
DEFAULT_RCFILE =
ZshOptions::RCFILE
DEFAULT_NUMBER =
5

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(histfile: DEFAULT_HISTFILE, rcfile: DEFAULT_RCFILE, number: DEFAULT_NUMBER, auto: false, config_file: CONFIG_FILE) ⇒ Runner

Returns a new instance of Runner.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/agen/runner.rb', line 12

def initialize(
  histfile: DEFAULT_HISTFILE,
  rcfile: DEFAULT_RCFILE,
  number: DEFAULT_NUMBER,
  auto: false,
  config_file: CONFIG_FILE
)
  @histfile = histfile
  @rcfile = rcfile
  @number = number
  @auto = auto
  @config_file = config_file
end

Instance Attribute Details

#histfileObject (readonly)

Returns the value of attribute histfile.



10
11
12
# File 'lib/agen/runner.rb', line 10

def histfile
  @histfile
end

#rcfileObject (readonly)

Returns the value of attribute rcfile.



10
11
12
# File 'lib/agen/runner.rb', line 10

def rcfile
  @rcfile
end

Instance Method Details

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/agen/runner.rb', line 26

def run
  commands = Finder.new(histfile).commands(limit: @number)
  @builder = Builder.new(commands, rcfile)
  aliases = builder.aliases

  # TODO: This could be its own class too
  File.open(rcfile, "a") do |file|
    puts "Writing new aliases to #{rcfile}:\n\n"
    aliases.each do |al|
      if auto
        write_auto(file, al[:full_alias])
      else
        write_interactive(file, al)
      end
    end
  end
end