ginbin 0.1.0 → 1.0.1

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: d68e01e4a606eb5d093ca7c4e623affdf539e78900e354156bb28ab85a0bb909
4
- data.tar.gz: 69b9c339366fe5188e382e72af90f26029d3cf4f0eb0a4a14d142c0fe6ae4b96
3
+ metadata.gz: 8ab104337df9ab99b20bb3e998ef303139ac398e6dc98ee30e732bf9ac5ddc38
4
+ data.tar.gz: 1be373d6b1246141c41db86a0c8fddc8c656f35d9a8afed95da0276039e54904
5
5
  SHA512:
6
- metadata.gz: 5fb3b44f7732402ca12b1b54392a9e52ff0e24ed33176b45183bb42ff00dee9223d9cbacd98361f462d7d3669e4db6ff7e222206d2617173695d0aad99a2b739
7
- data.tar.gz: deec65ab12b8b1822bae664b080bfc06e8903fc5001f6f5e09f546da58386b8df45d1e561ec76666f94ccbc77bb647ebf1903b5e50c4e7bbb752c8d926a4f50d
6
+ metadata.gz: 99a3108fb9b4b37e2a806f264655d70d423ea1a21b866e3bae0950f9a352e4f68fc6c5da39e714d381310add827ebf2d07c0817c96fe814c28c6abd669d3513b
7
+ data.tar.gz: 3f48182de2ab56d5ce59e4e3151ff97dedc4b51a9b3f4ef3df46b2f74a4d31f186ec6cdd0cea9119c26359387807772bbd591e2af46e86a2dcbd7dac3e8c4b00
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.1] - 2023-04-18
4
+
5
+ * replace deprecated `File.exists?`
6
+
7
+ ## [1.0.0] - 2022-08-29
8
+
9
+ * submenu
10
+
3
11
  ## [0.1.0] - 2022-06-10
4
12
 
5
- - Initial release
13
+ * Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ginbin (0.1.0)
4
+ ginbin (1.0.1)
5
5
  tty-prompt
6
6
 
7
7
  GEM
@@ -63,7 +63,9 @@ GEM
63
63
  wisper (2.0.1)
64
64
 
65
65
  PLATFORMS
66
+ arm64-darwin-22
66
67
  x86_64-darwin-21
68
+ x86_64-linux
67
69
 
68
70
  DEPENDENCIES
69
71
  ginbin!
data/README.md CHANGED
@@ -1,37 +1,44 @@
1
1
  # Ginbin
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ginbin`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Build interactive menu from most used shell commands.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ ## Install
6
6
 
7
- ## Installation
8
-
9
- Install the gem and add to the application's Gemfile by executing:
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
- TODO: Write usage instructions here
13
+ Create config ~/.ginbin.yml:
20
14
 
21
- ## Development
15
+ ```yaml
16
+ commands:
17
+ - title: "Connect to server"
18
+ cmd: ssh my-server.com -t "cd /opt/app && bash -l"
22
19
 
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.
20
+ - title: "Build report"
21
+ cmd: /usr/bin/report
24
22
 
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).
23
+ # short command desc without titlwe
24
+ - echo `date`
26
25
 
27
- ## Contributing
26
+ - menu: Submenu
27
+ commands:
28
+ - echo 1
29
+ - echo 2
28
30
 
29
- Bug reports and pull requests are welcome on GitHub at https://github.com/sergio-fry/ginbin. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/sergio-fry/ginbin/blob/master/CODE_OF_CONDUCT.md).
31
+ - menu: Sub Sumenu
32
+ commands:
33
+ - ssh server1
34
+ - ssh server2
30
35
 
31
- ## License
36
+ # any command could have a title
37
+ - title: Main server
38
+ cmd: ssh server-main
32
39
 
33
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+ ```
34
41
 
35
- ## Code of Conduct
42
+ Then run `ginbin`
36
43
 
37
- Everyone interacting in the Ginbin project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/sergio-fry/ginbin/blob/master/CODE_OF_CONDUCT.md).
44
+ It is also possible to have project-specific commands. Just put another .ginbin.yml inside current dir.
@@ -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 "commands"
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("Select an editor?", choices).call
18
+ prompt.enum_select("Choose command", choices).call
11
19
  end
12
20
 
13
21
  def choices
14
- commands.map do |command|
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ginbin
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.1"
5
5
  end
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.0
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: 2022-06-10 00:00:00.000000000 Z
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/commands.rb
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.3.7
74
+ rubygems_version: 3.4.10
74
75
  signing_key:
75
76
  specification_version: 4
76
77
  summary: Menu from your most used commands
@@ -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