agen 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac1f9e3386a6c2aa6a792d31040e869cd0cc2243335b0406d8636003cdd91737
4
- data.tar.gz: c8465c062ca6dba68556e80a22ba7600688f7a60e237c1e2f01352c6fffd7a1e
3
+ metadata.gz: dcbe6011253c346bb0abe4d9147146610cbc9fc98f7769f31b960ba20304af17
4
+ data.tar.gz: 5e8035ec1fb0aec32b660395ea24d6d5a8a88aa9e8cc88d0122115d6a2358150
5
5
  SHA512:
6
- metadata.gz: 2ce071d533b7af081c55e7cd1f91c8326a9145c4731c2e891e84c1b93544207df5159824646a78623707afd1e0bfb5d6062bdeab65bf94cd4afd1a8da0d58d7b
7
- data.tar.gz: 66138b4626cb5c8b257e5325904a9efd8d9ee8e3623bc59ec78e2b58e46e654c4b3ff90e1e702bb5b03c57c5218f9bb844330b4bf659a0184e0f1d54157b0f0a
6
+ metadata.gz: 4ca5c06be491092c201c8dcbce7623f0a887d4fbd52e36ab9afc27281ced79fbc97ecb878fc016f4c958893e82bd6718cd08f978c2619fc7a8f59bee7e84358a
7
+ data.tar.gz: 6e62b98c8745005dd1c1632abdc44adef8b55c9e47cfab0318652248b6e5df125109f378b53ca549c8521b6fa07bb70554397b09bcdb63e6bfdb24342f20e30b
data/CHANGELOG.md CHANGED
@@ -1,10 +1,9 @@
1
1
  ## [Released]
2
2
 
3
- ## [0.1.4] - 2021-04-24
4
- - Avoids most alias naming conflicts with commands that already exist (e.g. `ls`)
5
-
6
- ## [0.1.3] - 2021-04-24
3
+ ## [0.1.5] - 2021-04-24
7
4
 
8
5
  - Initial release that anyone should reasonably use.
9
6
  - Support for .zshrc/.zsh_history.
10
7
  - Automatically writes top 5 aliases for commands 6 characters or longer.
8
+ - Avoids most alias naming conflicts with commands that already exist (e.g. `ls`).
9
+ - Avoids duplicating aliases that have already been written.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- agen (0.1.4)
4
+ agen (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -23,24 +23,17 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Jonath
23
23
 
24
24
  ## Roadmap
25
25
 
26
- ~~1. CLI will read 5 most common full commands from .zsh_history file, and create
27
- an alias for them in the .zshrc file.~~
28
- - [x] It should handle a very short or shell history without many different
29
- commands.
30
- - [x] It should not create the same alias for two different commands in the same
31
- session.
32
- - [x] It should not create aliases for very short commands.
33
- ~~2. CLI should not duplicate aliases or commands that already exist on the system.~~
34
- 3. CLI will let you see proposed aliases and accept/decline them interactively. Maybe auto should be the default?
35
- OR, in "auto mode", commands will be added automatically (as in 1).
36
- 4. CLI should have helpful output for `-h/--help`.
37
- 5. CLI will let you specify number of aliases you want to create.
38
- 6. CLI will support any (or most common) shells, and will find history and rc
26
+ * CLI will let you specify number of aliases you want to create.
27
+ * CLI will let you see proposed aliases and accept/decline them interactively.
28
+ OR, in "auto mode", commands will be added automatically (as in 1). Auto
29
+ should be default?
30
+ * CLI should have helpful output for `-h/--help`.
31
+ * CLI will support any (or most common) shells, and will find history and rc
39
32
  file dynamically.
40
- 7. CLI will let you specific which history file to read form, and which file to output aliases to.
41
- 8. CLI will let you interactively modify proposed aliases.
42
- 9. CLI will let you "ignore" commands you don't want to alias, forever.
43
- 10. CLI will let you specify "meta" vs "full" commands.
33
+ * CLI will let you specific which history file to read form, and which file to output aliases to.
34
+ * CLI will let you interactively modify proposed aliases.
35
+ * CLI will let you "ignore" commands you don't want to alias, forever.
36
+ * CLI will let you specify "meta" vs "full" commands.
44
37
  - Full command would be `git checkout branch-name`, meta command would be
45
38
  `git checkout`.
46
39
 
data/lib/agen/builder.rb CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  module Agen
4
4
  class Builder
5
- def initialize(commands)
5
+ def initialize(commands, rcfile = Runner::DEFAULT_RCFILE)
6
6
  @commands = commands
7
+ @rcfile = rcfile
7
8
  end
8
9
 
9
10
  def aliases
@@ -17,8 +18,15 @@ module Agen
17
18
  aliaz += aliaz[-1]
18
19
  end
19
20
 
20
- "alias #{aliaz}=\"#{cmd}\""
21
- end
21
+ candidate = "alias #{aliaz}=\"#{cmd}\""
22
+ candidate if alias_does_not_exist?(candidate)
23
+ end.compact
24
+ end
25
+
26
+ private
27
+
28
+ def alias_does_not_exist?(aliaz)
29
+ File.readlines(@rcfile).none? { |line| line.include?(aliaz) }
22
30
  end
23
31
 
24
32
  # Shoutout to Stack Overflow: https://stackoverflow.com/a/5471032
data/lib/agen/runner.rb CHANGED
@@ -14,10 +14,10 @@ module Agen
14
14
 
15
15
  def run
16
16
  commands = Finder.new(histfile).commands
17
- aliases = Builder.new(commands).aliases
17
+ aliases = Builder.new(commands, rcfile).aliases
18
18
 
19
19
  File.open(rcfile, "a") do |file|
20
- puts "Writing aliases to #{rcfile}:"
20
+ puts "Writing new aliases to #{rcfile}:"
21
21
  aliases.each do |al|
22
22
  puts al
23
23
  file.puts(al)
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.1.4"
4
+ VERSION = "0.1.5"
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.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Thom