kuzya 0.0.1.1 → 0.0.2
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 +11 -0
- data/README.md +4 -11
- data/kuzya.gemspec +11 -5
- data/lib/kuzya/cli.rb +16 -18
- data/lib/kuzya/commands/add.rb +20 -22
- data/lib/kuzya/commands/base.rb +18 -18
- data/lib/kuzya/commands/help.rb +22 -25
- data/lib/kuzya/commands/list.rb +43 -41
- data/lib/kuzya/commands/open.rb +24 -28
- data/lib/kuzya/commands/remove.rb +18 -21
- data/lib/kuzya/commands/version.rb +22 -0
- data/lib/kuzya/commands.rb +11 -11
- data/lib/kuzya/config.rb +40 -44
- data/lib/kuzya/service.rb +3 -5
- data/lib/kuzya/url_builder.rb +16 -18
- data/lib/kuzya.rb +2 -0
- metadata +7 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5470ee51a09a0a749319011ec6c7953cdb52cd41157255681f1022ed9ea08cf7
|
|
4
|
+
data.tar.gz: 805b328585d384158e123ec79d5552acb5c15edf30327543b1bd477092fcecfc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b84aa1c1db641b163f3b9d39078089486a0d8be1d9aad1ef4a7b5cc4a63da1f096994c500ed1b4fbf1b06e8f47edf8cf0f9282c59c94d4a77829aae9ab254a00
|
|
7
|
+
data.tar.gz: bd1c559fa78a7a95f605cd2bef1ef1f45bf14386935a1d39ab85a6fa784bf3f052627a840beb18198368a2f4914012a809f464abd03f51869db2bc8b59346c1e
|
data/Changelog
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Version 0.0.2:
|
|
2
|
+
- new 'version' command
|
|
3
|
+
- Add aliases for commands:
|
|
4
|
+
- for 'version' command - '-v', '--version'
|
|
5
|
+
- for 'remove' command - 'rm'
|
|
6
|
+
- fix issue with backslash at the end of URL
|
|
7
|
+
- change license to MIT
|
|
8
|
+
- show broken urls in list
|
|
9
|
+
|
|
10
|
+
Version 0.0.1:
|
|
11
|
+
- Kuzya created.
|
data/README.md
CHANGED
|
@@ -4,6 +4,8 @@ __Kuzya__ - application to quickly open links from you terminal without mouse.
|
|
|
4
4
|
|
|
5
5
|
___
|
|
6
6
|
|
|
7
|
+
> Note: currently tested only on Linux
|
|
8
|
+
|
|
7
9
|
## How to install
|
|
8
10
|
|
|
9
11
|
### by rubygems
|
|
@@ -76,14 +78,5 @@ kuzya help
|
|
|
76
78
|
```
|
|
77
79
|
|
|
78
80
|
___
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
https://opensource.org/licenses/isc-license.txt
|
|
82
|
-
|
|
83
|
-
ISC License (ISC)
|
|
84
|
-
|
|
85
|
-
Copyright (c) 2021 Dmitry Krushinsky
|
|
86
|
-
|
|
87
|
-
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
88
|
-
|
|
89
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
81
|
+
## License
|
|
82
|
+
The gem is available as open source under the terms of the MIT License.
|
data/kuzya.gemspec
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'kuzya'
|
|
3
|
-
s.version = '0.0.
|
|
3
|
+
s.version = '0.0.2'
|
|
4
4
|
s.summary = 'Utility to open urls in browser from terminal.'
|
|
5
|
-
s.description =
|
|
6
|
-
s.
|
|
5
|
+
s.description = 'Utility to open urls in browser from terminal with shortcuts.'
|
|
6
|
+
s.homepage = 'https://github.com/d-krushinsky/kuzya'
|
|
7
|
+
if s.respond_to?(:metadata=)
|
|
8
|
+
s.metadata = {
|
|
9
|
+
'homepage_uri' => 'https://github.com/d-krushinsky/kuzya',
|
|
10
|
+
'source_code_uri' => 'https://github.com/d-krushinsky/kuzya'
|
|
11
|
+
}
|
|
12
|
+
end
|
|
7
13
|
s.author = 'Dmitry Krushinsky'
|
|
8
14
|
s.email = 'd.krushinsky.00@gmail.com'
|
|
9
15
|
s.files = `git ls-files`.split("\n")
|
|
10
|
-
s.license = '
|
|
11
|
-
s.required_ruby_version = Gem::Requirement.new(
|
|
16
|
+
s.license = 'MIT'
|
|
17
|
+
s.required_ruby_version = Gem::Requirement.new('>= 2.4.0'.freeze)
|
|
12
18
|
|
|
13
19
|
s.add_dependency 'launchy'
|
|
14
20
|
|
data/lib/kuzya/cli.rb
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
end
|
|
3
|
+
class Kuzya::CLI < Kuzya::Service
|
|
4
|
+
def initialize(args)
|
|
5
|
+
@args = args
|
|
6
|
+
end
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
def call
|
|
9
|
+
config = Kuzya::Config.new
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
build_command.call(args, config)
|
|
12
|
+
end
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
private
|
|
16
15
|
|
|
17
|
-
|
|
16
|
+
attr_reader :args
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
def build_command
|
|
19
|
+
command = Kuzya::Commands.fetch_command(args.first)
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
Object.const_get("Kuzya::Commands::#{command.capitalize}")
|
|
22
|
+
end
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
end
|
|
24
|
+
def args_without_command
|
|
25
|
+
args.dup.tap { |ary| ary.shift }
|
|
28
26
|
end
|
|
29
27
|
end
|
data/lib/kuzya/commands/add.rb
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class << self
|
|
7
|
-
def info
|
|
3
|
+
class Kuzya::Commands::Add < Kuzya::Commands::Base
|
|
4
|
+
class << self
|
|
5
|
+
def info
|
|
8
6
|
<<-INFO
|
|
9
7
|
#{'add'.bold} - to add new shortcut use #{'kuzya add short www.example.com'.italic}.
|
|
10
8
|
You can adds shortcuts inside other shurtcuts, e.g.
|
|
@@ -12,27 +10,27 @@ You can adds shortcuts inside other shurtcuts, e.g.
|
|
|
12
10
|
#{'kuzya add stack q questions'.italic}
|
|
13
11
|
#{'kuzya add stack q active ?tab=Active'.italic}
|
|
14
12
|
And now if run '#{'kuzya stack q active'.italic}' you will see all active questions
|
|
15
|
-
Note: You can't add first-level shortcuts named as [add, remove, list, help]
|
|
13
|
+
Note: You can't add first-level shortcuts named as [add, remove, rm, list, help, version, -v, --version]
|
|
16
14
|
INFO
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def prepare(args, config)
|
|
20
|
-
[args_without_command(args), config]
|
|
21
|
-
end
|
|
22
|
-
end
|
|
15
|
+
end
|
|
23
16
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
def prepare(args, config)
|
|
18
|
+
[args_without_command(args), config]
|
|
19
|
+
end
|
|
20
|
+
end
|
|
28
21
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
def initialize(args, config)
|
|
23
|
+
@args = args
|
|
24
|
+
@config = config
|
|
25
|
+
end
|
|
32
26
|
|
|
33
|
-
|
|
27
|
+
def call
|
|
28
|
+
config.add(args)
|
|
34
29
|
|
|
35
|
-
|
|
36
|
-
end
|
|
30
|
+
puts 'Done.'
|
|
37
31
|
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
attr_reader :args, :config
|
|
38
36
|
end
|
data/lib/kuzya/commands/base.rb
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
raise NotImplementedError
|
|
9
|
-
end
|
|
3
|
+
class Kuzya::Commands::Base
|
|
4
|
+
class << self
|
|
5
|
+
def info
|
|
6
|
+
raise NotImplementedError
|
|
7
|
+
end
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
def call(args, config)
|
|
10
|
+
new(*prepare(args, config)).call
|
|
11
|
+
end
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
# Returns array of arguments that will be passed to constructor
|
|
14
|
+
def prepare(_args, _config)
|
|
15
|
+
raise NotImplementedError
|
|
16
|
+
end
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
end
|
|
23
|
-
end
|
|
18
|
+
def args_without_command(args)
|
|
19
|
+
args.dup.tap { |ary| ary.shift }
|
|
24
20
|
end
|
|
25
21
|
end
|
|
22
|
+
|
|
23
|
+
def call
|
|
24
|
+
raise NotImplementedError
|
|
25
|
+
end
|
|
26
26
|
end
|
data/lib/kuzya/commands/help.rb
CHANGED
|
@@ -1,38 +1,35 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
].freeze
|
|
3
|
+
class Kuzya::Commands::Help < Kuzya::Commands::Base
|
|
4
|
+
SUPPORTED_COMMANDS = [
|
|
5
|
+
Kuzya::Commands::Open,
|
|
6
|
+
Kuzya::Commands::Help,
|
|
7
|
+
Kuzya::Commands::Version,
|
|
8
|
+
Kuzya::Commands::Add,
|
|
9
|
+
Kuzya::Commands::Remove,
|
|
10
|
+
Kuzya::Commands::List
|
|
11
|
+
].freeze
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
class << self
|
|
14
|
+
def info
|
|
16
15
|
<<-INFO
|
|
17
16
|
#{'help'.bold} - to read info about kuzya's commands run '#{'kuzya help'.italic}'
|
|
18
17
|
INFO
|
|
19
|
-
|
|
18
|
+
end
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
def prepare(_args, _config)
|
|
21
|
+
# Do nothing
|
|
22
|
+
end
|
|
23
|
+
end
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
def initialize
|
|
26
|
+
end
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
def call
|
|
29
|
+
puts "#{Kuzya::SUMMARY}\n\n"
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
end
|
|
35
|
-
end
|
|
31
|
+
SUPPORTED_COMMANDS.each do |command|
|
|
32
|
+
puts "#{command.info.to_s}\n"
|
|
36
33
|
end
|
|
37
34
|
end
|
|
38
35
|
end
|
data/lib/kuzya/commands/list.rb
CHANGED
|
@@ -1,59 +1,61 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class << self
|
|
7
|
-
def info
|
|
3
|
+
class Kuzya::Commands::List < Kuzya::Commands::Base
|
|
4
|
+
class << self
|
|
5
|
+
def info
|
|
8
6
|
<<-INFO
|
|
9
7
|
#{'list'.bold} - to see all shortcuts run '#{'kuzya list'.italic}'
|
|
10
8
|
INFO
|
|
11
|
-
|
|
9
|
+
end
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
def prepare(_args, config)
|
|
12
|
+
[config]
|
|
13
|
+
end
|
|
14
|
+
end
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
def initialize(config)
|
|
17
|
+
@config = config
|
|
18
|
+
end
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
def call
|
|
21
|
+
resolved = []
|
|
22
|
+
resolve_shortcuts([], [], fetch_keys(config.shortcuts), resolved)
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
resolved.each do |shortcuts|
|
|
25
|
+
puts "#{shortcuts.join(' ').bold}: #{build_url(shortcuts, config)}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
private
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
attr_reader :config
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
def fetch_keys(hash)
|
|
34
|
+
hash.dup.tap { |h| h.delete('_url') }.map do |key, value|
|
|
35
|
+
next key unless value.is_a?(Hash)
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
result = [key, fetch_keys(value)].reject(&:empty?)
|
|
38
|
+
result.length == 1 ? key : result
|
|
39
|
+
end.reject(&:empty?)
|
|
40
|
+
end
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
prev_com = com.dup
|
|
53
|
-
resolve_shortcuts(com, prev_com, arg, resolved)
|
|
54
|
-
com = []
|
|
55
|
-
end
|
|
42
|
+
def resolve_shortcuts(com, prev_com, shortcuts, resolved)
|
|
43
|
+
shortcuts.each do |arg|
|
|
44
|
+
if arg.is_a?(String)
|
|
45
|
+
com = prev_com.dup.concat([arg])
|
|
46
|
+
resolved.push(com)
|
|
47
|
+
next
|
|
56
48
|
end
|
|
49
|
+
|
|
50
|
+
prev_com = com.dup
|
|
51
|
+
resolve_shortcuts(com, prev_com, arg, resolved)
|
|
52
|
+
com = []
|
|
57
53
|
end
|
|
58
54
|
end
|
|
55
|
+
|
|
56
|
+
def build_url(shortcuts, config)
|
|
57
|
+
"#{Kuzya::UrlBuilder.call(shortcuts, config).italic}"
|
|
58
|
+
rescue
|
|
59
|
+
"#{'BROKEN URL'.red}".italic
|
|
60
|
+
end
|
|
59
61
|
end
|
data/lib/kuzya/commands/open.rb
CHANGED
|
@@ -2,43 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
require 'launchy'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
def info
|
|
12
|
-
<<-INFO
|
|
5
|
+
class Kuzya::Commands::Open < Kuzya::Commands::Base
|
|
6
|
+
URL_REGEXP = /\A#{URI::regexp(['http', 'https'])}\z/.freeze
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
def info
|
|
10
|
+
<<-INFO
|
|
13
11
|
#{'open'.bold} - to open any link run '#{'kuzya www.example.com'.italic}'
|
|
14
12
|
Also you can use your saved shortcuts instead of writing entire URL
|
|
15
13
|
e.g. add 'gh' shortcut as 'https://github.com' and 'rb' as 'ruby'
|
|
16
14
|
with 'kuzya add' command and run '#{'kuzya gh rb rake'.italic}'. Kuzya will make
|
|
17
15
|
the URL and open 'https://github.com/ruby/rake'.
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
INFO
|
|
17
|
+
end
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
def prepare(args, config)
|
|
20
|
+
[Kuzya::UrlBuilder.call(args, config)]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
def initialize(url)
|
|
25
|
+
@url = url
|
|
26
|
+
end
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
def call
|
|
29
|
+
puts "Open #{url}"
|
|
30
|
+
raise unless url =~ URL_REGEXP
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
Launchy.open(url)
|
|
33
|
+
rescue
|
|
34
|
+
puts "Can't open '#{url}', please check it, maybe you don't have shortcuts or URL is invalid".red
|
|
35
|
+
end
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
private
|
|
40
38
|
|
|
41
|
-
|
|
42
|
-
end
|
|
43
|
-
end
|
|
39
|
+
attr_reader :url
|
|
44
40
|
end
|
|
@@ -1,36 +1,33 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class << self
|
|
7
|
-
def info
|
|
3
|
+
class Kuzya::Commands::Remove < Kuzya::Commands::Base
|
|
4
|
+
class << self
|
|
5
|
+
def info
|
|
8
6
|
<<-INFO
|
|
9
7
|
#{'remove'.bold} - if you want to remove shortcut you can run:
|
|
10
8
|
#{'kuzya remove shortcut_name'.italic}
|
|
11
9
|
Also you can remove nested shortcuts, to do it run:
|
|
12
10
|
#{'kuzya remove parent_shortcut child_shortcut'.italic}
|
|
13
11
|
Note: Removing shortcut that have nested shortcuts also removes them
|
|
12
|
+
aliases: #{'rm'.italic}
|
|
14
13
|
INFO
|
|
15
|
-
|
|
14
|
+
end
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
def prepare(args, config)
|
|
17
|
+
[args_without_command(args), config]
|
|
18
|
+
end
|
|
19
|
+
end
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
def initialize(args, config)
|
|
22
|
+
@args = args
|
|
23
|
+
@config = config
|
|
24
|
+
end
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
def call
|
|
27
|
+
config.remove(args)
|
|
28
|
+
end
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
private
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
end
|
|
35
|
-
end
|
|
32
|
+
attr_reader :args, :config
|
|
36
33
|
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class Kuzya::Commands::Version < Kuzya::Commands::Base
|
|
4
|
+
class << self
|
|
5
|
+
def info
|
|
6
|
+
<<-INFO
|
|
7
|
+
#{'version'.bold} - print installed kuzya's version.
|
|
8
|
+
aliases: #{'-v'.italic}, #{'--version'.italic}
|
|
9
|
+
INFO
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def prepare(_, _)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def initialize
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def call
|
|
20
|
+
puts "kuzya - #{Kuzya::VERSION}"
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/kuzya/commands.rb
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Kuzya
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
module Kuzya::Commands
|
|
4
|
+
COMMANDS_MAPPING = {
|
|
5
|
+
/^(version|-v|--version)$/ => 'version',
|
|
6
|
+
/^(add)$/ => 'add',
|
|
7
|
+
/^(remove|rm)$/ => 'remove',
|
|
8
|
+
/^(list)$/ => 'list',
|
|
9
|
+
/^(help)$/ => 'help'
|
|
10
|
+
}.freeze
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
end
|
|
12
|
+
def self.fetch_command(first_arg)
|
|
13
|
+
COMMANDS_MAPPING.detect { |regex, _| first_arg =~ regex }&.[](1) || 'open'
|
|
15
14
|
end
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
require 'kuzya/commands/base'
|
|
18
|
+
require 'kuzya/commands/version'
|
|
19
19
|
require 'kuzya/commands/open'
|
|
20
20
|
require 'kuzya/commands/add'
|
|
21
21
|
require 'kuzya/commands/remove'
|
data/lib/kuzya/config.rb
CHANGED
|
@@ -3,65 +3,61 @@
|
|
|
3
3
|
require 'fileutils'
|
|
4
4
|
require 'yaml'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
PATH_TO_CONFIG = "#{Dir.home}/.kuzya/kuzya.yml".freeze
|
|
6
|
+
class Kuzya::Config
|
|
7
|
+
PATH_TO_DIR = "#{Dir.home}/.kuzya".freeze
|
|
8
|
+
PATH_TO_CONFIG = "#{Dir.home}/.kuzya/kuzya.yml".freeze
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
attr_reader :shortcuts
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
def add(keys)
|
|
20
|
-
value = keys.pop
|
|
12
|
+
def initialize
|
|
13
|
+
FileUtils.mkdir_p(PATH_TO_DIR) # Creates file if not exists
|
|
14
|
+
FileUtils.touch(PATH_TO_CONFIG) # Creating file if not exists
|
|
15
|
+
@shortcuts = YAML.load(File.read(PATH_TO_CONFIG)) || {}
|
|
16
|
+
end
|
|
21
17
|
|
|
22
|
-
|
|
18
|
+
def add(keys)
|
|
19
|
+
value = keys.pop
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
@shortcuts.deep_merge!(new_shortcut)
|
|
26
|
-
save
|
|
21
|
+
scan_shortcuts(keys)
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
new_shortcut = build_shortcut(keys, value)
|
|
24
|
+
@shortcuts.deep_merge!(new_shortcut)
|
|
25
|
+
save
|
|
26
|
+
end
|
|
30
27
|
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
def remove(keys)
|
|
29
|
+
scan_shortcuts(keys)
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
empty_shortcut = build_empty_shortcut(keys)
|
|
32
|
+
@shortcuts.deep_merge!(empty_shortcut)
|
|
33
|
+
@shortcuts = Hash.deep_compact(@shortcuts)
|
|
37
34
|
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
save
|
|
36
|
+
end
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
private
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
def save
|
|
41
|
+
File.open(PATH_TO_CONFIG, 'w') { |file| file.write(@shortcuts.to_yaml) }
|
|
42
|
+
end
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
def build_empty_shortcut(keys)
|
|
45
|
+
keys.reverse.inject(nil) { |assigned_value, key| { key => assigned_value } }
|
|
46
|
+
end
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
end
|
|
48
|
+
def build_shortcut(keys, value)
|
|
49
|
+
keys.reverse.inject({ '_url' => value }) do |assigned_value, key|
|
|
50
|
+
{ key => assigned_value }
|
|
55
51
|
end
|
|
52
|
+
end
|
|
56
53
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
def scan_shortcuts(keys)
|
|
55
|
+
shortcuts.dup do |hash|
|
|
56
|
+
keys.each do |key|
|
|
57
|
+
next hash = hash[key] if hash.key?(key)
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
end
|
|
59
|
+
puts "Key '#{key}' not found. Check spelling or add it by 'kuzya #{keys.join(' ')} www.example.com'."
|
|
60
|
+
exit(1)
|
|
65
61
|
end
|
|
66
62
|
end
|
|
67
63
|
end
|
data/lib/kuzya/service.rb
CHANGED
data/lib/kuzya/url_builder.rb
CHANGED
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
end
|
|
3
|
+
class Kuzya::UrlBuilder < Kuzya::Service
|
|
4
|
+
def initialize(args, config)
|
|
5
|
+
@args = args
|
|
6
|
+
@config = config
|
|
7
|
+
end
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
def call
|
|
10
|
+
url = ''
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
end
|
|
12
|
+
config.shortcuts.dup.tap do |conf|
|
|
13
|
+
args.each do |key|
|
|
14
|
+
conf = conf.fetch(key, { '_url' => key })
|
|
15
|
+
url += "#{conf.fetch('_url')}/"
|
|
18
16
|
end
|
|
19
|
-
|
|
20
|
-
url
|
|
21
17
|
end
|
|
22
18
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
attr_reader :config, :args
|
|
19
|
+
url.chop
|
|
26
20
|
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
attr_reader :config, :args
|
|
27
25
|
end
|
data/lib/kuzya.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kuzya
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dmitry Krushinsky
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-09-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: launchy
|
|
@@ -24,7 +24,7 @@ dependencies:
|
|
|
24
24
|
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '0'
|
|
27
|
-
description: Utility to open urls in browser from terminal.
|
|
27
|
+
description: Utility to open urls in browser from terminal with shortcuts.
|
|
28
28
|
email: d.krushinsky.00@gmail.com
|
|
29
29
|
executables:
|
|
30
30
|
- kuzya
|
|
@@ -32,6 +32,7 @@ extensions: []
|
|
|
32
32
|
extra_rdoc_files: []
|
|
33
33
|
files:
|
|
34
34
|
- ".gitignore"
|
|
35
|
+
- Changelog
|
|
35
36
|
- README.md
|
|
36
37
|
- bin/kuzya
|
|
37
38
|
- kuzya.gemspec
|
|
@@ -44,15 +45,16 @@ files:
|
|
|
44
45
|
- lib/kuzya/commands/list.rb
|
|
45
46
|
- lib/kuzya/commands/open.rb
|
|
46
47
|
- lib/kuzya/commands/remove.rb
|
|
48
|
+
- lib/kuzya/commands/version.rb
|
|
47
49
|
- lib/kuzya/config.rb
|
|
48
50
|
- lib/kuzya/core_ext/hash/deep_compact.rb
|
|
49
51
|
- lib/kuzya/core_ext/hash/deep_merge.rb
|
|
50
52
|
- lib/kuzya/core_ext/string/formatting.rb
|
|
51
53
|
- lib/kuzya/service.rb
|
|
52
54
|
- lib/kuzya/url_builder.rb
|
|
53
|
-
homepage:
|
|
55
|
+
homepage: https://github.com/d-krushinsky/kuzya
|
|
54
56
|
licenses:
|
|
55
|
-
-
|
|
57
|
+
- MIT
|
|
56
58
|
metadata:
|
|
57
59
|
homepage_uri: https://github.com/d-krushinsky/kuzya
|
|
58
60
|
source_code_uri: https://github.com/d-krushinsky/kuzya
|