completely 0.6.3 → 0.7.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/README.md +64 -25
- data/lib/completely/commands/init.rb +11 -2
- data/lib/completely/completions.rb +9 -12
- data/lib/completely/config.rb +69 -0
- data/lib/completely/templates/sample-nested.yaml +14 -0
- data/lib/completely/templates/sample.yaml +11 -14
- data/lib/completely/version.rb +1 -1
- data/lib/completely.rb +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ab14df9d4065650b0e776ea29552ef7cc01670bcac03e1ff180bb97412c2099
|
4
|
+
data.tar.gz: 3b0ba408058696ccf0b8d01c5ec230057900d1e9af246144a829229cce098705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b94ccf5f12af3764620cb90b0da5bee7a3306f7dd9f39b0b47e0715d7198cc96ca147c64a8eff243d555abb9ee52398a437f053499837df1563eef3d655f86d9
|
7
|
+
data.tar.gz: a5d7ea400c07344a899a33c55a84263cc5cf146f7039e8ed11e02e7ee728f326a19aa20c999c975f7d75046d998095a6a25e84815319fd06d5bc11d5fdb12ebf
|
data/README.md
CHANGED
@@ -40,10 +40,10 @@ or with Docker:
|
|
40
40
|
$ alias completely='docker run --rm -it --user $(id -u):$(id -g) --volume "$PWD:/app" dannyben/completely'
|
41
41
|
```
|
42
42
|
|
43
|
-
##
|
43
|
+
## Configuration syntax
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
Completely works with a simple YAML configuration file as input, and generates
|
46
|
+
a bash completions script as output.
|
47
47
|
|
48
48
|
The configuration file is built of blocks that look like this:
|
49
49
|
|
@@ -59,7 +59,7 @@ for the auto complete process.
|
|
59
59
|
|
60
60
|
You can save a sample YAML file by running:
|
61
61
|
|
62
|
-
```
|
62
|
+
```bash
|
63
63
|
$ completely init
|
64
64
|
```
|
65
65
|
|
@@ -67,37 +67,34 @@ This will generate a file named `completely.yaml` with this content:
|
|
67
67
|
|
68
68
|
```yaml
|
69
69
|
mygit:
|
70
|
+
- -h
|
71
|
+
- -v
|
70
72
|
- --help
|
71
73
|
- --version
|
72
|
-
- status
|
73
74
|
- init
|
74
|
-
-
|
75
|
+
- status
|
76
|
+
|
77
|
+
mygit init:
|
78
|
+
- --bare
|
79
|
+
- <directory>
|
75
80
|
|
76
81
|
mygit status:
|
77
82
|
- --help
|
78
83
|
- --verbose
|
79
84
|
- --branch
|
80
|
-
-
|
85
|
+
- -b
|
81
86
|
|
82
|
-
mygit
|
83
|
-
- --
|
84
|
-
- <directory>
|
87
|
+
mygit status*--branch: &branches
|
88
|
+
- $(git branch --format='%(refname:short)' 2>/dev/null)
|
85
89
|
|
86
|
-
mygit
|
87
|
-
- <file>
|
88
|
-
- --help
|
89
|
-
- --message
|
90
|
-
- --all
|
91
|
-
- -a
|
92
|
-
- --quiet
|
93
|
-
- -q
|
90
|
+
mygit status*-b: *branches
|
94
91
|
```
|
95
92
|
|
96
93
|
Each pattern in this configuration file will be checked against the user's
|
97
|
-
input, and if the input
|
98
|
-
|
94
|
+
input, and if the input matches the pattern, the list that follows it will be
|
95
|
+
suggested as completions.
|
99
96
|
|
100
|
-
Note that the suggested completions will not show flags (
|
97
|
+
Note that the suggested completions will not show flags (strings that start with
|
101
98
|
a hyphen `-`) unless the input ends with a hyphen.
|
102
99
|
|
103
100
|
To generate the bash script, simply run:
|
@@ -169,7 +166,7 @@ branches to your suggestions, use the following:
|
|
169
166
|
|
170
167
|
```yaml
|
171
168
|
mygit:
|
172
|
-
- $(git branch 2>/dev/null)
|
169
|
+
- $(git branch --format='%(refname:short)' 2>/dev/null)
|
173
170
|
```
|
174
171
|
|
175
172
|
The `2> /dev/null` is used so that if the command is executed in a directory
|
@@ -186,10 +183,10 @@ mygit checkout:
|
|
186
183
|
- -b
|
187
184
|
|
188
185
|
mygit checkout*--branch:
|
189
|
-
- $(git branch 2>/dev/null)
|
186
|
+
- $(git branch --format='%(refname:short)' 2>/dev/null)
|
190
187
|
|
191
188
|
mygit checkout*-b:
|
192
|
-
- $(git branch 2>/dev/null)
|
189
|
+
- $(git branch --format='%(refname:short)' 2>/dev/null)
|
193
190
|
```
|
194
191
|
|
195
192
|
The above will suggest git branches for commands that end with `-b` or `--branch`.
|
@@ -202,11 +199,53 @@ mygit checkout:
|
|
202
199
|
- -b
|
203
200
|
|
204
201
|
mygit checkout*--branch: &branches
|
205
|
-
- $(git branch 2>/dev/null)
|
202
|
+
- $(git branch --format='%(refname:short)' 2>/dev/null)
|
206
203
|
|
207
204
|
mygit checkout*-b: *branches
|
208
205
|
```
|
209
206
|
|
207
|
+
### Alternative nested syntax
|
208
|
+
|
209
|
+
Completely also supports an alternative nested syntax. You can generate this
|
210
|
+
example by running:
|
211
|
+
|
212
|
+
```bash
|
213
|
+
$ completely init --nested
|
214
|
+
```
|
215
|
+
|
216
|
+
The example configuration below will generate the exact same script as the one
|
217
|
+
shown at the beginning of this document.
|
218
|
+
|
219
|
+
```yaml
|
220
|
+
mygit:
|
221
|
+
- -h
|
222
|
+
- -v
|
223
|
+
- --help
|
224
|
+
- --version
|
225
|
+
- init:
|
226
|
+
- --bare
|
227
|
+
- <directory>
|
228
|
+
- status:
|
229
|
+
- --help
|
230
|
+
- --verbose
|
231
|
+
- +--branch: &branches
|
232
|
+
- $(git branch --format='%(refname:short)' 2>/dev/null)
|
233
|
+
- +-b: *branches
|
234
|
+
```
|
235
|
+
|
236
|
+
The rules here are as follows:
|
237
|
+
|
238
|
+
- Each pattern (e.g., `mygit`) can have a mixed array of strings and hashes.
|
239
|
+
- Strings and hash keys (e.e., `--help` and `init` respectively) will be used
|
240
|
+
as completion strings for that pattern.
|
241
|
+
- Hashes may contain a nested mixed array of the same structure.
|
242
|
+
- When a hash is provided, the hash key will be appended to the parent prefix.
|
243
|
+
In the example above, the `init` hash will create the pattern `mygit init`.
|
244
|
+
- In order to provide a wildcard (like `mygit status*--branch` in the standard
|
245
|
+
configuration syntax), you can provide either a `*` or a `+` prefix to the
|
246
|
+
hash key (e.g., `+--branch` or `"*--branch"`). Note that when using a `*`,
|
247
|
+
the hash key must be quoted since asterisks have special meaning in YAML.
|
248
|
+
|
210
249
|
## Using the generated completion scripts
|
211
250
|
|
212
251
|
In order to enable the completions, simply source the generated script:
|
@@ -5,9 +5,11 @@ module Completely
|
|
5
5
|
class Init < Base
|
6
6
|
help 'Create a new sample YAML configuration file'
|
7
7
|
|
8
|
-
usage 'completely init [CONFIG_PATH]'
|
8
|
+
usage 'completely init [--nested] [CONFIG_PATH]'
|
9
9
|
usage 'completely init (-h|--help)'
|
10
10
|
|
11
|
+
option '-n --nested', 'Generate a nested configuration'
|
12
|
+
|
11
13
|
param_config_path
|
12
14
|
environment_config_path
|
13
15
|
|
@@ -24,8 +26,15 @@ module Completely
|
|
24
26
|
@sample ||= File.read sample_path
|
25
27
|
end
|
26
28
|
|
29
|
+
def nested?
|
30
|
+
args['--nested']
|
31
|
+
end
|
32
|
+
|
27
33
|
def sample_path
|
28
|
-
@sample_path ||=
|
34
|
+
@sample_path ||= begin
|
35
|
+
sample_name = nested? ? 'sample-nested' : 'sample'
|
36
|
+
File.expand_path "../templates/#{sample_name}.yaml", __dir__
|
37
|
+
end
|
29
38
|
end
|
30
39
|
end
|
31
40
|
end
|
@@ -7,23 +7,20 @@ module Completely
|
|
7
7
|
|
8
8
|
class << self
|
9
9
|
def load(config_path, function_name: nil)
|
10
|
-
|
11
|
-
|
12
|
-
rescue ArgumentError
|
13
|
-
# :nocov:
|
14
|
-
data = YAML.load_file config_path
|
15
|
-
# :nocov:
|
16
|
-
end
|
17
|
-
|
18
|
-
new data, function_name: function_name
|
10
|
+
config = Config.load config_path
|
11
|
+
new config, function_name: function_name
|
19
12
|
end
|
20
13
|
end
|
21
14
|
|
22
15
|
def initialize(config, function_name: nil)
|
23
|
-
@config = config
|
16
|
+
@config = config.is_a?(Config) ? config : Config.new(config)
|
24
17
|
@function_name = function_name
|
25
18
|
end
|
26
19
|
|
20
|
+
def flat_config
|
21
|
+
@flat_config ||= config.flat_config
|
22
|
+
end
|
23
|
+
|
27
24
|
def patterns
|
28
25
|
@patterns ||= patterns!
|
29
26
|
end
|
@@ -54,7 +51,7 @@ module Completely
|
|
54
51
|
private
|
55
52
|
|
56
53
|
def patterns!
|
57
|
-
result =
|
54
|
+
result = flat_config.map do |text, completions|
|
58
55
|
Pattern.new text, completions, pattern_function_name
|
59
56
|
end
|
60
57
|
|
@@ -70,7 +67,7 @@ module Completely
|
|
70
67
|
end
|
71
68
|
|
72
69
|
def command
|
73
|
-
@command ||=
|
70
|
+
@command ||= flat_config.keys.first.split.first
|
74
71
|
end
|
75
72
|
|
76
73
|
def function_name
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Completely
|
2
|
+
class Config
|
3
|
+
attr_reader :config
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def load(config_path)
|
7
|
+
begin
|
8
|
+
config = YAML.load_file config_path, aliases: true
|
9
|
+
rescue ArgumentError
|
10
|
+
# :nocov:
|
11
|
+
config = YAML.load_file config_path
|
12
|
+
# :nocov:
|
13
|
+
end
|
14
|
+
|
15
|
+
new config
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(config)
|
20
|
+
@config = config
|
21
|
+
end
|
22
|
+
|
23
|
+
def flat_config
|
24
|
+
result = {}
|
25
|
+
|
26
|
+
config.each do |root_key, root_list|
|
27
|
+
result.merge! process_key(root_key, root_list)
|
28
|
+
end
|
29
|
+
|
30
|
+
result
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def process_key(prefix, list)
|
36
|
+
result = {}
|
37
|
+
result[prefix] = collect_immediate_children list
|
38
|
+
result.merge! process_nested_items(prefix, list)
|
39
|
+
result
|
40
|
+
end
|
41
|
+
|
42
|
+
def collect_immediate_children(list)
|
43
|
+
list.map do |item|
|
44
|
+
x = item.is_a?(Hash) ? item.keys.first : item
|
45
|
+
x.gsub(/^[*+]/, '')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def process_nested_items(prefix, list)
|
50
|
+
result = {}
|
51
|
+
|
52
|
+
list.each do |item|
|
53
|
+
next unless item.is_a? Hash
|
54
|
+
|
55
|
+
nested_prefix = generate_nested_prefix(prefix, item)
|
56
|
+
nested_list = item.values.first
|
57
|
+
result.merge!(process_key(nested_prefix, nested_list))
|
58
|
+
end
|
59
|
+
|
60
|
+
result
|
61
|
+
end
|
62
|
+
|
63
|
+
def generate_nested_prefix(prefix, item)
|
64
|
+
appended_prefix = item.keys.first.gsub(/^\+/, '*')
|
65
|
+
appended_prefix = " #{appended_prefix}" unless appended_prefix.start_with? '*'
|
66
|
+
"#{prefix}#{appended_prefix}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -1,25 +1,22 @@
|
|
1
1
|
mygit:
|
2
|
+
- -h
|
3
|
+
- -v
|
2
4
|
- --help
|
3
5
|
- --version
|
4
|
-
- status
|
5
6
|
- init
|
6
|
-
-
|
7
|
+
- status
|
8
|
+
|
9
|
+
mygit init:
|
10
|
+
- --bare
|
11
|
+
- <directory>
|
7
12
|
|
8
13
|
mygit status:
|
9
14
|
- --help
|
10
15
|
- --verbose
|
11
16
|
- --branch
|
12
|
-
-
|
17
|
+
- -b
|
13
18
|
|
14
|
-
mygit
|
15
|
-
- --
|
16
|
-
- <directory>
|
19
|
+
mygit status*--branch: &branches
|
20
|
+
- $(git branch --format='%(refname:short)' 2>/dev/null)
|
17
21
|
|
18
|
-
mygit
|
19
|
-
- <file>
|
20
|
-
- --help
|
21
|
-
- --message
|
22
|
-
- --all
|
23
|
-
- -a
|
24
|
-
- --quiet
|
25
|
-
- -q
|
22
|
+
mygit status*-b: *branches
|
data/lib/completely/version.rb
CHANGED
data/lib/completely.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: completely
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -63,9 +63,11 @@ files:
|
|
63
63
|
- lib/completely/commands/test.rb
|
64
64
|
- lib/completely/commands/uninstall.rb
|
65
65
|
- lib/completely/completions.rb
|
66
|
+
- lib/completely/config.rb
|
66
67
|
- lib/completely/exceptions.rb
|
67
68
|
- lib/completely/installer.rb
|
68
69
|
- lib/completely/pattern.rb
|
70
|
+
- lib/completely/templates/sample-nested.yaml
|
69
71
|
- lib/completely/templates/sample.yaml
|
70
72
|
- lib/completely/templates/template.erb
|
71
73
|
- lib/completely/templates/tester-template.erb
|
@@ -94,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
96
|
- !ruby/object:Gem::Version
|
95
97
|
version: '0'
|
96
98
|
requirements: []
|
97
|
-
rubygems_version: 3.5.
|
99
|
+
rubygems_version: 3.5.23
|
98
100
|
signing_key:
|
99
101
|
specification_version: 4
|
100
102
|
summary: Bash Completions Generator
|