completely 0.1.3 → 0.2.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 +34 -12
- data/lib/completely/command.rb +7 -0
- data/lib/completely/completions.rb +8 -0
- data/lib/completely/pattern.rb +9 -1
- data/lib/completely/sample.yaml +1 -0
- data/lib/completely/template.erb +3 -2
- data/lib/completely/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54ee6b84395ab00c6d0fdde61065b9843b178947a7569cea41cead7b149ef55b
|
4
|
+
data.tar.gz: 3dd72641e530c42b0642b5861f1b38c219b5931846ed2da7fb20648563954094
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8f2ffa6f7f8303e827c8bb894accf1d97ae0e012f46d495dcfab280836ffd5ae8aa0418b95450a41642bb1fcabb9b2ee2d54ef037f88e43f048a6014ae4acff
|
7
|
+
data.tar.gz: 94f01f524b7ffc8bf5ca910594e203f1579bccc0910795ca2a74cf64af5838dab1b023a250f017da9c0c2798c68ac71149657c14a3f587a32a30268843fdd815
|
data/README.md
CHANGED
@@ -32,15 +32,18 @@ $ gem install completely
|
|
32
32
|
The `completely` command line works with a simple YAML configuration file as
|
33
33
|
input, and generates a bash completions script as output.
|
34
34
|
|
35
|
-
The configuration file is built like this:
|
35
|
+
The configuration file is built of blocks that look like this:
|
36
36
|
|
37
37
|
```yaml
|
38
38
|
pattern:
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
- --argument
|
40
|
+
- --param
|
41
|
+
- command
|
42
42
|
```
|
43
43
|
|
44
|
+
Each pattern contains an array of words (or functions) that will be suggested
|
45
|
+
for the auto complete process.
|
46
|
+
|
44
47
|
You can save a sample YAML file by running:
|
45
48
|
|
46
49
|
```
|
@@ -61,6 +64,7 @@ mygit status:
|
|
61
64
|
- --help
|
62
65
|
- --verbose
|
63
66
|
- --branch
|
67
|
+
- $(git branch 2> /dev/null)
|
64
68
|
|
65
69
|
mygit init:
|
66
70
|
- --bare
|
@@ -97,19 +101,23 @@ $ completely --help
|
|
97
101
|
|
98
102
|
### Suggesting files, directories and other bash built-ins
|
99
103
|
|
100
|
-
|
104
|
+
In addition to specifying a simple array of completion words, you may use
|
105
|
+
the special syntax `<..>` to suggest more advanced functions.
|
101
106
|
|
102
|
-
|
103
|
-
|
107
|
+
```yaml
|
108
|
+
pattern:
|
109
|
+
- <file>
|
110
|
+
- <directory>
|
111
|
+
```
|
104
112
|
|
105
|
-
These
|
113
|
+
These suggestions will add the list of files and directories
|
106
114
|
(when `<file>` is used) or just directories (when `<directory>` is used) to
|
107
115
|
the list of suggestions.
|
108
116
|
|
109
|
-
You may
|
117
|
+
You may use any of the below keywords to add additional suggestions:
|
110
118
|
|
111
|
-
| Keyword
|
112
|
-
|
119
|
+
| Keyword | Meaning
|
120
|
+
|---------------|---------------------
|
113
121
|
| `<alias>` | Alias names
|
114
122
|
| `<arrayvar>` | Array variable names
|
115
123
|
| `<binding>` | Readline key binding names
|
@@ -137,6 +145,20 @@ For those interested in the technical details, any word between `<...>` will
|
|
137
145
|
simply be added using the [`compgen -A action`][compgen] function, so you can
|
138
146
|
in fact use any of its supported arguments.
|
139
147
|
|
148
|
+
### Suggesting custom dynamic suggestions
|
149
|
+
|
150
|
+
You can also use any command that outputs a whitespace-delimited list as a
|
151
|
+
suggestions list, by wrapping it in `$(..)`. For example, in order to add git
|
152
|
+
branches to your suggestions, use the following:
|
153
|
+
|
154
|
+
```yaml
|
155
|
+
mygit:
|
156
|
+
- $(git branch 2> /dev/null)
|
157
|
+
```
|
158
|
+
|
159
|
+
The `2> /dev/null` is used so that if the command is executed in a directory
|
160
|
+
without a git repository, it will still behave as expected.
|
161
|
+
|
140
162
|
|
141
163
|
## Using the generated completion scripts
|
142
164
|
|
@@ -182,4 +204,4 @@ to contribute, feel free to [open an issue][issues].
|
|
182
204
|
|
183
205
|
[issues]: https://github.com/DannyBen/completely/issues
|
184
206
|
[compgen]: https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html
|
185
|
-
[bashly]: https://
|
207
|
+
[bashly]: https://bashly.dannyb.co/
|
data/lib/completely/command.rb
CHANGED
@@ -37,6 +37,7 @@ module Completely
|
|
37
37
|
|
38
38
|
def preview_command
|
39
39
|
puts script
|
40
|
+
syntax_warning unless completions.valid?
|
40
41
|
end
|
41
42
|
|
42
43
|
def generate_command
|
@@ -44,6 +45,7 @@ module Completely
|
|
44
45
|
output = wrap ? wrapper_function(wrap) : script
|
45
46
|
File.write output_path, output
|
46
47
|
say "Saved !txtpur!#{output_path}"
|
48
|
+
syntax_warning unless completions.valid?
|
47
49
|
end
|
48
50
|
|
49
51
|
private
|
@@ -76,5 +78,10 @@ module Completely
|
|
76
78
|
@completions ||= Completions.load(config_path, function_name: args['--function'])
|
77
79
|
end
|
78
80
|
|
81
|
+
def syntax_warning
|
82
|
+
say! "\n!txtred!WARNING:\nYour configuration is invalid."
|
83
|
+
say! "!txtred!All patterns must start with the same word."
|
84
|
+
end
|
85
|
+
|
79
86
|
end
|
80
87
|
end
|
@@ -19,6 +19,10 @@ module Completely
|
|
19
19
|
@patterns ||= patterns!
|
20
20
|
end
|
21
21
|
|
22
|
+
def valid?
|
23
|
+
pattern_prefixes.uniq.count == 1
|
24
|
+
end
|
25
|
+
|
22
26
|
def script
|
23
27
|
ERB.new(template, trim_mode: '%-').result(binding)
|
24
28
|
end
|
@@ -58,5 +62,9 @@ module Completely
|
|
58
62
|
@function_name ||= "_#{command}_completions"
|
59
63
|
end
|
60
64
|
|
65
|
+
def pattern_prefixes
|
66
|
+
patterns.map &:prefix
|
67
|
+
end
|
68
|
+
|
61
69
|
end
|
62
70
|
end
|
data/lib/completely/pattern.rb
CHANGED
data/lib/completely/sample.yaml
CHANGED
data/lib/completely/template.erb
CHANGED
@@ -5,11 +5,12 @@
|
|
5
5
|
# Modifying it manually is not recommended
|
6
6
|
<%= function_name %>() {
|
7
7
|
local cur=${COMP_WORDS[COMP_CWORD]}
|
8
|
+
local comp_line="${COMP_WORDS[*]:1}"
|
8
9
|
|
9
|
-
case "$
|
10
|
+
case "$comp_line" in
|
10
11
|
% patterns.each do |pattern|
|
11
12
|
% next if pattern.empty?
|
12
|
-
'<%= pattern.
|
13
|
+
'<%= pattern.text_without_prefix %>'*) COMPREPLY=($(compgen <%= pattern.compgen %> -- "$cur")) ;;
|
13
14
|
% end
|
14
15
|
esac
|
15
16
|
}
|
data/lib/completely/version.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.2.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: 2021-
|
11
|
+
date: 2021-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
|
-
rubygems_version: 3.2.
|
77
|
+
rubygems_version: 3.2.25
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Bash Completions Generator
|