agen 0.2.1 → 0.3

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: 567b4d1df4a054da853eb05a9476bcf9579758cac435e562842c74655e773198
4
- data.tar.gz: 86e7947aac95a1fc80822158509b1d2e762a11727eca8abda0001b7de87d2115
3
+ metadata.gz: edd821d0314f78d537a2228181e4f1dfd0ecaceddc8d8a67bb783499911e7ccb
4
+ data.tar.gz: 721e0d0871630027ac23c0e08d7dd54e3e20ef26fda674fe755ebb02e0e4be48
5
5
  SHA512:
6
- metadata.gz: cbaead32095bc304c5bf657426fa66f5b7196c90715a8b8466b597fc578d2c49414f25533bc815946b6bdf20c51af877299bdc3bcba886b4d575864fca04f324
7
- data.tar.gz: 1c2b2388b097b4f7a95036be7395569d81b3de1e33630a2ffa1b5c262898dbda59742a62a6d88e9d0eb615dcba2375cbf7430472aeb99a77efe03fefa61e60c5
6
+ metadata.gz: f2c802aa56ab03338dbe58638a5ab5cf525c13ffef6b0a6b11e5aff39b430d4645f3116d6d49e37425df1704029148ca8df3d8d5dc4af84d0b3dff8ff8263d1c
7
+ data.tar.gz: d02a95bbee062a61ebe93160c03f773706e45264b09cd4cae9a2aab2c1a45c97078192b399466854e22e87d80266c6aa29e61167ce3f8b726b4a07180311a450
@@ -12,5 +12,7 @@ jobs:
12
12
  with:
13
13
  ruby-version: 3.0.1
14
14
  bundler-cache: true
15
- - name: Run the default task
15
+ - name: Lint
16
+ run: bundle exec rake standard
17
+ - name: Test
16
18
  run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Released]
2
2
 
3
+ ## [0.3] - 2021-06-17
4
+ - Adds support for bash shell.
5
+ - Adds ability to pass custom rcfile and histfile options.
6
+
3
7
  ## [0.2.1] - 2021-05-01
4
8
  - Adds ability to modify aliases before writing them in interactive mode.
5
9
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- agen (0.2.1)
4
+ agen (0.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -4,6 +4,9 @@
4
4
 
5
5
  Generate shell aliases based on your most commonly entered commands.
6
6
 
7
+ https://user-images.githubusercontent.com/22665228/116796045-5e5a8280-aa8e-11eb-8b4c-4408a252c143.mov
8
+
9
+
7
10
  ## Installation & Usage
8
11
 
9
12
  Install with `gem install agen` and then run `agen` to build your aliases. Then
@@ -14,10 +17,11 @@ available options.
14
17
  Usage: agen [options]
15
18
  -n, --number=NUMBER Number of aliases to generate
16
19
  -a, --auto Aliases will be generated and applied automatically
20
+ -r, --rcfile=RCFILE Path to shell rc file
21
+ -h, --histfile=HISTFILE Path to shell history file
17
22
  ```
18
23
 
19
- Right now, this will only work with `zsh`, but support for other shells is on
20
- the very lengthy todo list. By default, agen reads from `.zsh_history` and
24
+ Right now, this will only work with `zsh` or `bash`, but you can specify unique shell config files using the `-r` and `-h` options (though there is no guarantee that your history file will be read properly). By default, agen reads from `.zsh_history` and
21
25
  writes to `.zshrc`.
22
26
 
23
27
  ## Development
@@ -32,14 +36,10 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Jonath
32
36
 
33
37
  ## Roadmap
34
38
 
35
- * CLI will support any (or most common) shells, and will find history and rc
36
- file dynamically.
37
- * CLI will let you specific which history file to read from, and which file to output aliases to.
38
- * CLI will let you interactively modify proposed aliases.
39
39
  * CLI will let you "ignore" commands you don't want to alias, forever.
40
+ * CLI will raise user friendly errors if you specify shell configuration files that don't exist.
40
41
  * CLI will let you specify "meta" vs "full" commands.
41
- - Full command would be `git checkout branch-name`, meta command would be
42
- `git checkout`.
42
+ - Full command would be `git checkout branch-name`, meta command would be `git checkout`.
43
43
 
44
44
  ## License
45
45
 
data/lib/agen.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "agen/version"
4
+ require_relative "agen/base_options"
5
+ require_relative "agen/bash_options"
6
+ require_relative "agen/zsh_options"
7
+ require_relative "agen/shell"
4
8
  require_relative "agen/cli"
5
9
  require_relative "agen/builder"
6
10
  require_relative "agen/finder"
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Agen
4
+ class BaseOptions
5
+ def initialize(options)
6
+ @options = options
7
+ end
8
+
9
+ def set_histfile
10
+ # handle not set here
11
+ if !defined?(self.class::HISTFILE)
12
+ puts "Please specify shell history file with -h option. See agen --help."
13
+ return false
14
+ end
15
+
16
+ options.tap do |opts|
17
+ opts[:histfile] = self.class::HISTFILE
18
+ end
19
+ end
20
+
21
+ def set_rcfile
22
+ if !defined?(self.class::RCFILE)
23
+ puts "Please specify shell rc file with -r option. See agen --help."
24
+ return false
25
+ end
26
+
27
+ options.tap do |opts|
28
+ opts[:rcfile] = self.class::RCFILE
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ attr_reader :options
35
+ end
36
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Agen
4
+ class BashOptions < BaseOptions
5
+ HISTFILE = "#{Dir.home}/.bash_history"
6
+ RCFILE = "#{Dir.home}/.bashrc"
7
+ end
8
+ end
data/lib/agen/cli.rb CHANGED
@@ -21,8 +21,19 @@ module Agen
21
21
  opts.on("-a", "--auto", "Aliases will be generated and applied automatically") do |a|
22
22
  options[:auto] = a
23
23
  end
24
+
25
+ opts.on("-rRCFILE", "--rcfile=RCFILE", String, "Path to shell rc file") do |r|
26
+ options[:rcfile] = r
27
+ end
28
+
29
+ opts.on("-hHISTFILE", "--histfile=HISTFILE", String, "Path to shell history file") do |h|
30
+ options[:histfile] = h
31
+ end
24
32
  end.parse!
25
33
 
34
+ options = Shell.new(options).add_options
35
+ return unless options
36
+
26
37
  Runner.new(**options).run
27
38
  end
28
39
  end
data/lib/agen/finder.rb CHANGED
@@ -14,7 +14,8 @@ module Agen
14
14
  .each_with_object(Hash.new(0)) do |line, commands|
15
15
  cmd = line.split(";").last.delete("\n")
16
16
  commands[cmd] += 1 if cmd != ""
17
- rescue
17
+ rescue => e
18
+ puts e
18
19
  end
19
20
  .sort_by { |k, v| -v }
20
21
  .to_h
data/lib/agen/runner.rb CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Agen
4
4
  class Runner
5
- DEFAULT_HISTFILE = "#{Dir.home}/.zsh_history"
6
- DEFAULT_RCFILE = "#{Dir.home}/.zshrc"
5
+ DEFAULT_HISTFILE = ZshOptions::HISTFILE
6
+ DEFAULT_RCFILE = ZshOptions::RCFILE
7
7
  DEFAULT_NUMBER = 5
8
8
 
9
9
  attr_reader :histfile, :rcfile
data/lib/agen/shell.rb ADDED
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Agen
4
+ class Shell
5
+ def initialize(options)
6
+ @options = options
7
+ end
8
+
9
+ def add_options
10
+ if !@options[:histfile]
11
+ @options = opts_klass.set_histfile
12
+ end
13
+
14
+ if @options && !@options[:rcfile]
15
+ @options = opts_klass.set_rcfile
16
+ end
17
+
18
+ @options
19
+ end
20
+
21
+ private
22
+
23
+ def bash?
24
+ @_bash ||= shell.match?(/bash/)
25
+ end
26
+
27
+ def opts_klass
28
+ @_opts_klass ||= if bash?
29
+ BashOptions
30
+ elsif zsh?
31
+ ZshOptions
32
+ else
33
+ BaseOptions
34
+ end.new(@options)
35
+ end
36
+
37
+ def shell
38
+ @_shell ||= ENV["SHELL"]
39
+ end
40
+
41
+ def zsh?
42
+ @_zsh ||= shell.match?(/zsh/)
43
+ end
44
+ end
45
+ 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.1"
4
+ VERSION = "0.3"
5
5
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Agen
4
+ class ZshOptions < BaseOptions
5
+ HISTFILE = "#{Dir.home}/.zsh_history"
6
+ RCFILE = "#{Dir.home}/.zshrc"
7
+ end
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Thom
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-01 00:00:00.000000000 Z
11
+ date: 2021-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -75,11 +75,15 @@ files:
75
75
  - bin/setup
76
76
  - exe/agen
77
77
  - lib/agen.rb
78
+ - lib/agen/base_options.rb
79
+ - lib/agen/bash_options.rb
78
80
  - lib/agen/builder.rb
79
81
  - lib/agen/cli.rb
80
82
  - lib/agen/finder.rb
81
83
  - lib/agen/runner.rb
84
+ - lib/agen/shell.rb
82
85
  - lib/agen/version.rb
86
+ - lib/agen/zsh_options.rb
83
87
  homepage: https://github.com/JonathanWThom/agen
84
88
  licenses:
85
89
  - MIT