agen 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +62 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +11 -0
- data/agen.gemspec +34 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/agen +7 -0
- data/lib/agen.rb +11 -0
- data/lib/agen/builder.rb +16 -0
- data/lib/agen/cli.rb +14 -0
- data/lib/agen/finder.rb +15 -0
- data/lib/agen/runner.rb +26 -0
- data/lib/agen/version.rb +5 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: acebf067e22c29311b6a91e2b24e5e8c3f822e24ec8d0a3b5221721e8c147b6a
|
4
|
+
data.tar.gz: 55129b76da51036069bfbc0890af80ef6b0d2ff57479666cd92d833327e81263
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 385c8d66a02051d68bce4de28b3c81c8fb106c509e2f2bfa14825dd4440b21399f3060ddee26a78ba6e5e3638a34429d1c992cb04d12939b9bad935ef00373d0
|
7
|
+
data.tar.gz: 433e67ddc92ac47d02c9618a1741bde74e3c8bd0f8621f1f4488270ea6d30a69f2664fd40c14eb97f70ae2f578e97c9180a969c66a5bae869d3b1fdf9c59df15
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 3.0.1
|
14
|
+
bundler-cache: true
|
15
|
+
- name: Run the default task
|
16
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Ruby 3.0.1
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
agen (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
parallel (1.20.1)
|
12
|
+
parser (3.0.1.0)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
rainbow (3.0.0)
|
15
|
+
rake (13.0.3)
|
16
|
+
regexp_parser (2.1.1)
|
17
|
+
rexml (3.2.5)
|
18
|
+
rspec (3.10.0)
|
19
|
+
rspec-core (~> 3.10.0)
|
20
|
+
rspec-expectations (~> 3.10.0)
|
21
|
+
rspec-mocks (~> 3.10.0)
|
22
|
+
rspec-core (3.10.1)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-expectations (3.10.1)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-mocks (3.10.2)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-support (3.10.2)
|
31
|
+
rubocop (1.12.1)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 3.0.0.0)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
regexp_parser (>= 1.8, < 3.0)
|
36
|
+
rexml
|
37
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
38
|
+
ruby-progressbar (~> 1.7)
|
39
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
40
|
+
rubocop-ast (1.4.1)
|
41
|
+
parser (>= 2.7.1.5)
|
42
|
+
rubocop-performance (1.10.1)
|
43
|
+
rubocop (>= 0.90.0, < 2.0)
|
44
|
+
rubocop-ast (>= 0.4.0)
|
45
|
+
ruby-progressbar (1.11.0)
|
46
|
+
standard (1.0.5)
|
47
|
+
rubocop (= 1.12.1)
|
48
|
+
rubocop-performance (= 1.10.1)
|
49
|
+
unicode-display_width (2.0.0)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
x86_64-darwin-20
|
53
|
+
x86_64-linux
|
54
|
+
|
55
|
+
DEPENDENCIES
|
56
|
+
agen!
|
57
|
+
rake
|
58
|
+
rspec
|
59
|
+
standard
|
60
|
+
|
61
|
+
BUNDLED WITH
|
62
|
+
2.2.16
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Jonathan Thom
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Agen
|
2
|
+
|
3
|
+
Generate shell aliases based on commonly entered commands.
|
4
|
+
|
5
|
+
## Roadmap
|
6
|
+
|
7
|
+
1. CLI will read 5 most common full commands from .zsh_history file, and create
|
8
|
+
an alias for them in the .zshrc file.
|
9
|
+
- It should not create aliases out of old aliases.
|
10
|
+
- It should handle a very short or shell history without many different
|
11
|
+
commands.
|
12
|
+
- It should output progress for very long/slow shell histories.
|
13
|
+
- It should not create the same alias for two different commands in the same
|
14
|
+
session.
|
15
|
+
- It should not create an alias that is longer than the original command.
|
16
|
+
1. CLI will let you see proposed aliases and accept/decline them interactively.
|
17
|
+
OR, in "auto mode", commands will be added automatically (as in 1).
|
18
|
+
1. CLI should have helpful output for `-h/--help`.
|
19
|
+
1. CLI will let you specify number of aliases you want to create.
|
20
|
+
1. CLI will support any (or most common) shells, and will find history and rc
|
21
|
+
file dynamically.
|
22
|
+
1. CLI will let you specific which history file to read form, and which file to output aliases to.
|
23
|
+
1. CLI will let you interactively modify proposed aliases.
|
24
|
+
1. CLI will let you "ignore" commands you don't want to alias, forever.
|
25
|
+
1. CLI will let you specify "meta" vs "full" commands.
|
26
|
+
- Full command would be `git checkout branch-name`, meta command would be
|
27
|
+
`git checkout`.
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
Add this line to your application's Gemfile:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
gem 'agen'
|
35
|
+
```
|
36
|
+
|
37
|
+
And then execute:
|
38
|
+
|
39
|
+
$ bundle install
|
40
|
+
|
41
|
+
Or install it yourself as:
|
42
|
+
|
43
|
+
$ gem install agen
|
44
|
+
|
45
|
+
## Usage
|
46
|
+
|
47
|
+
TODO: Write usage instructions here
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/agen.
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/agen.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/agen/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "agen"
|
7
|
+
spec.version = Agen::VERSION
|
8
|
+
spec.authors = ["Jonathan Thom"]
|
9
|
+
spec.email = ["jonathanthom@hey.com"]
|
10
|
+
|
11
|
+
spec.summary = "Generate shell aliases based on commonly entered commands."
|
12
|
+
spec.homepage = "https://github.com/JonathanWThom/agen"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
spec.metadata["changelog_uri"] = "https://github.com/JonathanWThom/agen/blob/main/CHANGELOG.md"
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "rake"
|
32
|
+
spec.add_development_dependency "rspec"
|
33
|
+
spec.add_development_dependency "standard"
|
34
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "agen"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/agen
ADDED
data/lib/agen.rb
ADDED
data/lib/agen/builder.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Agen
|
4
|
+
class Builder
|
5
|
+
def initialize(commands)
|
6
|
+
@commands = commands
|
7
|
+
end
|
8
|
+
|
9
|
+
def aliases
|
10
|
+
@commands.map do |cmd|
|
11
|
+
aliaz = cmd.scan(/\b\w/).join
|
12
|
+
"alias #{aliaz}=\"#{cmd}\""
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/agen/cli.rb
ADDED
data/lib/agen/finder.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Agen
|
4
|
+
class Finder
|
5
|
+
def initialize(histfile)
|
6
|
+
@histfile = histfile
|
7
|
+
end
|
8
|
+
|
9
|
+
def commands(limit = 5)
|
10
|
+
File.readlines(@histfile).reverse.each_with_object(Hash.new(0)) do |line, commands|
|
11
|
+
commands[line.split(";").last.delete("\n")] += 1
|
12
|
+
end.sort_by { |k, v| -v }.to_h.keys.first(limit)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/agen/runner.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Agen
|
4
|
+
class Runner
|
5
|
+
DEFAULT_HISTFILE = "#{Dir.home}/.zsh_history"
|
6
|
+
DEFAULT_RCFILE = "#{Dir.home}/.zshrc"
|
7
|
+
|
8
|
+
attr_reader :histfile, :rcfile
|
9
|
+
|
10
|
+
def initialize(histfile: DEFAULT_HISTFILE, rcfile: DEFAULT_RCFILE)
|
11
|
+
@histfile = histfile
|
12
|
+
@rcfile = rcfile
|
13
|
+
end
|
14
|
+
|
15
|
+
def run
|
16
|
+
commands = Finder.new(histfile).commands
|
17
|
+
aliases = Builder.new(commands).aliases
|
18
|
+
|
19
|
+
File.open(rcfile, "a") do |file|
|
20
|
+
aliases.each do |al|
|
21
|
+
file.puts(al)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/agen/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: agen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Thom
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: standard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- jonathanthom@hey.com
|
58
|
+
executables:
|
59
|
+
- agen
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".github/workflows/main.yml"
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".tool-versions"
|
67
|
+
- CHANGELOG.md
|
68
|
+
- Gemfile
|
69
|
+
- Gemfile.lock
|
70
|
+
- LICENSE.txt
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- agen.gemspec
|
74
|
+
- bin/console
|
75
|
+
- bin/setup
|
76
|
+
- exe/agen
|
77
|
+
- lib/agen.rb
|
78
|
+
- lib/agen/builder.rb
|
79
|
+
- lib/agen/cli.rb
|
80
|
+
- lib/agen/finder.rb
|
81
|
+
- lib/agen/runner.rb
|
82
|
+
- lib/agen/version.rb
|
83
|
+
homepage: https://github.com/JonathanWThom/agen
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata:
|
87
|
+
allowed_push_host: https://rubygems.org
|
88
|
+
homepage_uri: https://github.com/JonathanWThom/agen
|
89
|
+
source_code_uri: https://github.com/JonathanWThom/agen
|
90
|
+
changelog_uri: https://github.com/JonathanWThom/agen/blob/main/CHANGELOG.md
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 2.4.0
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubygems_version: 3.2.15
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Generate shell aliases based on commonly entered commands.
|
110
|
+
test_files: []
|