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 +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile.lock +1 -1
- data/lib/agen/builder.rb +7 -3
- data/lib/agen/runner.rb +30 -13
- data/lib/agen/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 567b4d1df4a054da853eb05a9476bcf9579758cac435e562842c74655e773198
|
4
|
+
data.tar.gz: 86e7947aac95a1fc80822158509b1d2e762a11727eca8abda0001b7de87d2115
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
-
|
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
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 =
|
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
|
-
|
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,
|
44
|
-
puts
|
45
|
-
file.puts(
|
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
|
-
|
53
|
-
|
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