ginbin 0.1.0 → 1.0.1
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 +9 -1
- data/Gemfile.lock +3 -1
- data/README.md +28 -21
- data/lib/ginbin/items.rb +24 -0
- data/lib/ginbin/items_from_config.rb +29 -0
- data/lib/ginbin/menu.rb +11 -7
- data/lib/ginbin/version.rb +1 -1
- metadata +5 -4
- data/lib/ginbin/commands.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ab104337df9ab99b20bb3e998ef303139ac398e6dc98ee30e732bf9ac5ddc38
|
4
|
+
data.tar.gz: 1be373d6b1246141c41db86a0c8fddc8c656f35d9a8afed95da0276039e54904
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99a3108fb9b4b37e2a806f264655d70d423ea1a21b866e3bae0950f9a352e4f68fc6c5da39e714d381310add827ebf2d07c0817c96fe814c28c6abd669d3513b
|
7
|
+
data.tar.gz: 3f48182de2ab56d5ce59e4e3151ff97dedc4b51a9b3f4ef3df46b2f74a4d31f186ec6cdd0cea9119c26359387807772bbd591e2af46e86a2dcbd7dac3e8c4b00
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,37 +1,44 @@
|
|
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
|
-
|
13
|
+
Create config ~/.ginbin.yml:
|
20
14
|
|
21
|
-
|
15
|
+
```yaml
|
16
|
+
commands:
|
17
|
+
- title: "Connect to server"
|
18
|
+
cmd: ssh my-server.com -t "cd /opt/app && bash -l"
|
22
19
|
|
23
|
-
|
20
|
+
- title: "Build report"
|
21
|
+
cmd: /usr/bin/report
|
24
22
|
|
25
|
-
|
23
|
+
# short command desc without titlwe
|
24
|
+
- echo `date`
|
26
25
|
|
27
|
-
|
26
|
+
- menu: Submenu
|
27
|
+
commands:
|
28
|
+
- echo 1
|
29
|
+
- echo 2
|
28
30
|
|
29
|
-
|
31
|
+
- menu: Sub Sumenu
|
32
|
+
commands:
|
33
|
+
- ssh server1
|
34
|
+
- ssh server2
|
30
35
|
|
31
|
-
|
36
|
+
# any command could have a title
|
37
|
+
- title: Main server
|
38
|
+
cmd: ssh server-main
|
32
39
|
|
33
|
-
|
40
|
+
```
|
34
41
|
|
35
|
-
|
42
|
+
Then run `ginbin`
|
36
43
|
|
37
|
-
|
44
|
+
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
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Ginbin
|
4
|
+
class ItemsFromConfig
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def each
|
8
|
+
(local_items + home_items).each do |item|
|
9
|
+
yield item
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def local_items
|
14
|
+
return [] if at_home?
|
15
|
+
return [] unless File.exist? '.ginbin.yml'
|
16
|
+
YAML.load_file('.ginbin.yml')["commands"]
|
17
|
+
end
|
18
|
+
|
19
|
+
def home_items
|
20
|
+
return [] unless File.exist? File.join(Dir.home, '.ginbin.yml')
|
21
|
+
|
22
|
+
YAML.load_file(File.join(Dir.home, '.ginbin.yml'))["commands"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def at_home?
|
26
|
+
Dir.getwd == Dir.home
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
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: 0.1
|
4
|
+
version: 1.0.1
|
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:
|
11
|
+
date: 2023-04-18 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
|
@@ -70,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
71
|
- !ruby/object:Gem::Version
|
71
72
|
version: '0'
|
72
73
|
requirements: []
|
73
|
-
rubygems_version: 3.
|
74
|
+
rubygems_version: 3.4.10
|
74
75
|
signing_key:
|
75
76
|
specification_version: 4
|
76
77
|
summary: Menu from your most used commands
|
data/lib/ginbin/commands.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require "ginbin/command"
|
2
|
-
require 'yaml'
|
3
|
-
|
4
|
-
module Ginbin
|
5
|
-
class Commands
|
6
|
-
include Enumerable
|
7
|
-
|
8
|
-
def each
|
9
|
-
(local_commads + home_commads).each do |command_desc|
|
10
|
-
if command_desc['title'].nil?
|
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
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def local_commads
|
19
|
-
return [] if at_home?
|
20
|
-
return [] unless File.exists? '.ginbin.yml'
|
21
|
-
YAML.load_file('.ginbin.yml')["commands"]
|
22
|
-
end
|
23
|
-
|
24
|
-
def home_commads
|
25
|
-
return [] unless File.exists? File.join(Dir.home, '.ginbin.yml')
|
26
|
-
|
27
|
-
YAML.load_file(File.join(Dir.home, '.ginbin.yml'))["commands"]
|
28
|
-
end
|
29
|
-
|
30
|
-
def at_home?
|
31
|
-
Dir.getwd == Dir.home
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|