agen 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 774809f0ab3f7e1b8bab9f9209f71f2e616f5da62edf2bf74f8f47f15d82b5ad
4
- data.tar.gz: 20e8af719cc7093968b107a32d98963febb0b03e1c9dddda3a111e1170cded9a
3
+ metadata.gz: 567b4d1df4a054da853eb05a9476bcf9579758cac435e562842c74655e773198
4
+ data.tar.gz: 86e7947aac95a1fc80822158509b1d2e762a11727eca8abda0001b7de87d2115
5
5
  SHA512:
6
- metadata.gz: 66e2e642b09fc276d27ad922f219be8431c2dc2014726227189c1d2a2cb28960a061cb2da11d45fddc9dce5ff292bb70136b71fd8ebd0ca36f9f015385048686
7
- data.tar.gz: 1b6beea0fb2a953cd710dc02974ce50aa1198234807cc776e1a5dfd0010dad241f9dbc160c89456b455749381601d9e5d0e03ab198997590068e48cec650cdae
6
+ metadata.gz: cbaead32095bc304c5bf657426fa66f5b7196c90715a8b8466b597fc578d2c49414f25533bc815946b6bdf20c51af877299bdc3bcba886b4d575864fca04f324
7
+ data.tar.gz: 1c2b2388b097b4f7a95036be7395569d81b3de1e33630a2ffa1b5c262898dbda59742a62a6d88e9d0eb615dcba2375cbf7430472aeb99a77efe03fefa61e60c5
data/CHANGELOG.md CHANGED
@@ -1,7 +1,11 @@
1
1
  ## [Released]
2
2
 
3
+ ## [0.2.1] - 2021-05-01
4
+ - Adds ability to modify aliases before writing them in interactive mode.
5
+
3
6
  ## [0.2.0] - 2021-04-30
4
- - Fix: Ensures the same aliases is not built for multiple commands in the same run.
7
+ - Adds interactive mode, allowing aliases to be accepted or rejected. On by
8
+ default.
5
9
 
6
10
  ## [0.1.7] - 2021-04-26
7
11
  - Fix: Ensures the same aliases is not built for multiple commands in the same run.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- agen (0.2.0)
4
+ agen (0.2.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/agen/builder.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Agen
4
4
  class Builder
5
- def initialize(commands, rcfile = Runner::DEFAULT_RCFILE)
5
+ def initialize(commands = [], rcfile = Runner::DEFAULT_RCFILE)
6
6
  @commands = commands
7
7
  @rcfile = rcfile
8
8
  end
@@ -19,14 +19,18 @@ module Agen
19
19
  aliaz += aliaz[-1]
20
20
  end
21
21
 
22
- candidate = "alias #{aliaz}=\"#{cmd}\""
22
+ candidate = construct_alias(aliaz, cmd)
23
23
  if alias_does_not_exist?(candidate)
24
24
  aliases << aliaz
25
- candidate
25
+ {alias: aliaz, full_alias: candidate, command: cmd}
26
26
  end
27
27
  end.compact
28
28
  end
29
29
 
30
+ def construct_alias(aliaz, cmd)
31
+ "alias #{aliaz}=\"#{cmd}\""
32
+ end
33
+
30
34
  private
31
35
 
32
36
  def alias_does_not_exist?(aliaz)
data/lib/agen/runner.rb CHANGED
@@ -22,13 +22,15 @@ module Agen
22
22
 
23
23
  def run
24
24
  commands = Finder.new(histfile).commands(limit: @number)
25
- aliases = Builder.new(commands, rcfile).aliases
25
+ @builder = Builder.new(commands, rcfile)
26
+ aliases = builder.aliases
26
27
 
28
+ # TODO: This could be its own class too
27
29
  File.open(rcfile, "a") do |file|
28
- puts "Writing new aliases to #{rcfile}:"
30
+ puts "Writing new aliases to #{rcfile}:\n\n"
29
31
  aliases.each do |al|
30
32
  if auto
31
- write_auto(file, al)
33
+ write_auto(file, al[:full_alias])
32
34
  else
33
35
  write_interactive(file, al)
34
36
  end
@@ -38,25 +40,40 @@ module Agen
38
40
 
39
41
  private
40
42
 
41
- attr_reader :auto
43
+ attr_reader :auto, :builder
42
44
 
43
- def write_auto(file, aliaz)
44
- puts aliaz
45
- file.puts(aliaz)
45
+ def write_auto(file, full_alias)
46
+ puts full_alias
47
+ file.puts(full_alias)
46
48
  end
47
49
 
48
50
  def write_interactive(file, aliaz)
49
- puts "Proposed alias: #{aliaz}"
50
- print "Accept? [n to reject, any other key to accept]: "
51
+ puts "Proposed alias: #{aliaz[:full_alias]}"
52
+ print "Accept? [n to reject, m to modify alias, any other key to accept]: "
51
53
  response = gets.chomp
52
- if response != "n"
53
- file.puts(aliaz)
54
- puts "Alias written"
55
- else
54
+ case response
55
+ when "n"
56
56
  puts "Alias skipped"
57
+ when "m"
58
+ modify_alias(file, aliaz)
59
+ else
60
+ file.puts(aliaz[:full_alias])
61
+ puts "Alias written"
57
62
  end
58
63
 
59
64
  puts
60
65
  end
66
+
67
+ def modify_alias(file, aliaz)
68
+ print "Enter new alias [replacing #{aliaz[:alias]}]: "
69
+ replacement = gets.chomp
70
+ if replacement == ""
71
+ modify_alias(file, aliaz)
72
+ return
73
+ end
74
+
75
+ file.puts(builder.construct_alias(replacement, aliaz[:command]))
76
+ puts "Alias written"
77
+ end
61
78
  end
62
79
  end
data/lib/agen/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Agen
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Thom