ginbin 0.1.0 → 1.0.0
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 +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile.lock +1 -1
- data/README.md +21 -24
- data/lib/ginbin/items.rb +24 -0
- data/lib/ginbin/{commands.rb → items_from_config.rb} +5 -10
- data/lib/ginbin/menu.rb +11 -7
- data/lib/ginbin/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 373ed38b8d48b1ca35609c3252b55e4f06376ea0658bf274e4b55aed33b80c08
|
4
|
+
data.tar.gz: 0b081671fe299110ad55a1bfa202f02bf436808139a2116a287298c403b3644d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adef20ff41ae6b103b5e8efec4580d1e623f1fa01ee3f3793ab198dd9d88059930fde679725b02395efe03c28f44ae73eb44c8fe64688625ce578f4f4ce5f72e
|
7
|
+
data.tar.gz: 850e5f347a4d5d9b923a7e1be9eab86718d472bdfc240aafa78282c885265abdffec042da2d920dc94e3a7ad8eca70e87e47ba9e353d8ff2b9862186d938efcb
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,37 +1,34 @@
|
|
1
1
|
# Ginbin
|
2
2
|
|
3
|
-
|
3
|
+
Build interactive menu from most used shell commands.
|
4
4
|
|
5
|
-
|
5
|
+
## Install
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
$ bundle add ginbin
|
12
|
-
|
13
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
-
|
15
|
-
$ gem install ginbin
|
7
|
+
```bash
|
8
|
+
gem install ginbin
|
9
|
+
```
|
16
10
|
|
17
11
|
## Usage
|
18
12
|
|
19
|
-
|
20
|
-
|
21
|
-
## Development
|
22
|
-
|
23
|
-
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.
|
24
|
-
|
25
|
-
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).
|
13
|
+
Create config ~/.ginbin.yml:
|
26
14
|
|
27
|
-
|
15
|
+
```yaml
|
16
|
+
commands:
|
17
|
+
- title: "Connect to server"
|
18
|
+
cmd: ssh my-server.com -t "cd /opt/app && bash -l"
|
28
19
|
|
29
|
-
|
20
|
+
- title: "Build report"
|
21
|
+
cmd: /usr/bin/report
|
30
22
|
|
31
|
-
|
23
|
+
# short command desc without titlwe
|
24
|
+
- echo `date`
|
32
25
|
|
33
|
-
|
26
|
+
- menu: Submenu
|
27
|
+
commands:
|
28
|
+
- echo 1
|
29
|
+
- echo 2
|
30
|
+
```
|
34
31
|
|
35
|
-
|
32
|
+
Then run `ginbin`
|
36
33
|
|
37
|
-
|
34
|
+
It is also possible to have project-specific commands. Just put another .ginbin.yml inside current dir.
|
data/lib/ginbin/items.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "ginbin/command"
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Ginbin
|
5
|
+
class Items
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
def initialize(items)
|
9
|
+
@items = items
|
10
|
+
end
|
11
|
+
|
12
|
+
def each
|
13
|
+
(@items).each do |item|
|
14
|
+
if !item['menu'].nil?
|
15
|
+
yield Menu.new(items: item['commands'], title: item['menu'])
|
16
|
+
elsif item['title'].nil?
|
17
|
+
yield Command.new(cmd: item, title: item)
|
18
|
+
else
|
19
|
+
yield Command.new(cmd: item['cmd'], title: item['title'])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,27 +1,22 @@
|
|
1
|
-
require "ginbin/command"
|
2
1
|
require 'yaml'
|
3
2
|
|
4
3
|
module Ginbin
|
5
|
-
class
|
4
|
+
class ItemsFromConfig
|
6
5
|
include Enumerable
|
7
6
|
|
8
7
|
def each
|
9
|
-
(
|
10
|
-
|
11
|
-
yield Command.new(cmd: command_desc, title: command_desc)
|
12
|
-
else
|
13
|
-
yield Command.new(cmd: command_desc['cmd'], title: command_desc['title'])
|
14
|
-
end
|
8
|
+
(local_items + home_items).each do |item|
|
9
|
+
yield item
|
15
10
|
end
|
16
11
|
end
|
17
12
|
|
18
|
-
def
|
13
|
+
def local_items
|
19
14
|
return [] if at_home?
|
20
15
|
return [] unless File.exists? '.ginbin.yml'
|
21
16
|
YAML.load_file('.ginbin.yml')["commands"]
|
22
17
|
end
|
23
18
|
|
24
|
-
def
|
19
|
+
def home_items
|
25
20
|
return [] unless File.exists? File.join(Dir.home, '.ginbin.yml')
|
26
21
|
|
27
22
|
YAML.load_file(File.join(Dir.home, '.ginbin.yml'))["commands"]
|
data/lib/ginbin/menu.rb
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
require "tty-prompt"
|
2
2
|
|
3
|
-
require_relative "
|
3
|
+
require_relative "items"
|
4
|
+
require_relative "items_from_config"
|
4
5
|
|
5
6
|
module Ginbin
|
6
7
|
class Menu
|
8
|
+
attr_reader :title
|
9
|
+
|
10
|
+
def initialize(items: ItemsFromConfig.new, title: "Root")
|
11
|
+
@items = items
|
12
|
+
@title = title
|
13
|
+
end
|
14
|
+
|
7
15
|
def call
|
8
16
|
prompt = TTY::Prompt.new
|
9
17
|
|
10
|
-
prompt.enum_select("
|
18
|
+
prompt.enum_select("Choose command", choices).call
|
11
19
|
end
|
12
20
|
|
13
21
|
def choices
|
14
|
-
|
22
|
+
Items.new(@items).map do |command|
|
15
23
|
{ name: command.title, value: command }
|
16
24
|
end
|
17
25
|
end
|
18
|
-
|
19
|
-
def commands
|
20
|
-
Commands.new
|
21
|
-
end
|
22
26
|
end
|
23
27
|
end
|
data/lib/ginbin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ginbin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergei O. Udalov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tty-prompt
|
@@ -45,7 +45,8 @@ files:
|
|
45
45
|
- ginbin.gemspec
|
46
46
|
- lib/ginbin.rb
|
47
47
|
- lib/ginbin/command.rb
|
48
|
-
- lib/ginbin/
|
48
|
+
- lib/ginbin/items.rb
|
49
|
+
- lib/ginbin/items_from_config.rb
|
49
50
|
- lib/ginbin/menu.rb
|
50
51
|
- lib/ginbin/version.rb
|
51
52
|
- sig/ginbin.rbs
|