completely 0.1.2 → 0.1.3
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 +33 -2
- data/lib/completely.rb +1 -1
- data/lib/completely/completions.rb +11 -5
- data/lib/completely/pattern.rb +42 -0
- data/lib/completely/template.erb +3 -6
- data/lib/completely/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8b8cc9f26134e125f8d8ec1d24081bdd3c22217e916c9233b00b471381fadc6
|
4
|
+
data.tar.gz: a161403557ba173302233a3f4c3a4b61b084157f648709b1c79627f48aac9c97
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22d3aa7b9db836ed7977d8888f46412184ea05d8de95632476275b6a33905308556d240014e816a01c47d9d56a35dd3181aec02eec149996587803db3fc47699
|
7
|
+
data.tar.gz: a0796eedf218a01c54ba31cdb63a7a9db747ec83eb5f37726fcd67e9b201291b3f6856b28a0323310bbaf613dec3f710a2d667b6ee02751d38d391e20c079287
|
data/README.md
CHANGED
@@ -13,7 +13,10 @@ This tool is for you if:
|
|
13
13
|
|
14
14
|
1. You develop your own command line tools.
|
15
15
|
2. Your life feels empty without bash completions.
|
16
|
-
3. Bash completion scripts
|
16
|
+
3. Bash completion scripts seem overly complex to you.
|
17
|
+
|
18
|
+
Note that if you are building bash command line scripts with [bashly][bashly],
|
19
|
+
then this functionality is already integrated with it.
|
17
20
|
|
18
21
|
---
|
19
22
|
|
@@ -92,7 +95,7 @@ For more options (like setting input/output path), run
|
|
92
95
|
$ completely --help
|
93
96
|
```
|
94
97
|
|
95
|
-
### Suggesting files and
|
98
|
+
### Suggesting files, directories and other bash built-ins
|
96
99
|
|
97
100
|
You may have noticed that the sample file contains two special entries:
|
98
101
|
|
@@ -103,6 +106,33 @@ These patterns will add the list of files and directories
|
|
103
106
|
(when `<file>` is used) or just directories (when `<directory>` is used) to
|
104
107
|
the list of suggestions.
|
105
108
|
|
109
|
+
You may add any of the below keywords to add additional suggestions:
|
110
|
+
|
111
|
+
| Keyword | Meaning
|
112
|
+
|-------------|---------------------
|
113
|
+
| `<alias>` | Alias names
|
114
|
+
| `<arrayvar>` | Array variable names
|
115
|
+
| `<binding>` | Readline key binding names
|
116
|
+
| `<builtin>` | Names of shell builtin commands
|
117
|
+
| `<command>` | Command names
|
118
|
+
| `<directory>` | Directory names
|
119
|
+
| `<disabled>` | Names of disabled shell builtins
|
120
|
+
| `<enabled>` | Names of enabled shell builtins
|
121
|
+
| `<export>` | Names of exported shell variables
|
122
|
+
| `<file>` | File names
|
123
|
+
| `<function>` | Names of shell functions
|
124
|
+
| `<group>` | Group names
|
125
|
+
| `<helptopic>` | Help topics as accepted by the help builtin
|
126
|
+
| `<hostname>` | Hostnames, as taken from the file specified by the HOSTFILE shell variable
|
127
|
+
| `<job>` | Job names
|
128
|
+
| `<keyword>` | Shell reserved words
|
129
|
+
| `<running>` | Names of running jobs
|
130
|
+
| `<service>` | Service names
|
131
|
+
| `<signal>` | Signal names
|
132
|
+
| `<stopped>` | Names of stopped jobs
|
133
|
+
| `<user>` | User names
|
134
|
+
| `<variable>` | Names of all shell variables
|
135
|
+
|
106
136
|
For those interested in the technical details, any word between `<...>` will
|
107
137
|
simply be added using the [`compgen -A action`][compgen] function, so you can
|
108
138
|
in fact use any of its supported arguments.
|
@@ -152,3 +182,4 @@ to contribute, feel free to [open an issue][issues].
|
|
152
182
|
|
153
183
|
[issues]: https://github.com/DannyBen/completely/issues
|
154
184
|
[compgen]: https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html
|
185
|
+
[bashly]: https://github.com/DannyBen/bashly
|
data/lib/completely.rb
CHANGED
@@ -15,6 +15,10 @@ module Completely
|
|
15
15
|
@config, @function_name = config, function_name
|
16
16
|
end
|
17
17
|
|
18
|
+
def patterns
|
19
|
+
@patterns ||= patterns!
|
20
|
+
end
|
21
|
+
|
18
22
|
def script
|
19
23
|
ERB.new(template, trim_mode: '%-').result(binding)
|
20
24
|
end
|
@@ -32,6 +36,12 @@ module Completely
|
|
32
36
|
|
33
37
|
private
|
34
38
|
|
39
|
+
def patterns!
|
40
|
+
config.map do |text, completions|
|
41
|
+
Pattern.new text, completions
|
42
|
+
end.sort_by { |pattern| -pattern.length }
|
43
|
+
end
|
44
|
+
|
35
45
|
def template_path
|
36
46
|
@template_path ||= File.expand_path("template.erb", __dir__)
|
37
47
|
end
|
@@ -41,11 +51,7 @@ module Completely
|
|
41
51
|
end
|
42
52
|
|
43
53
|
def command
|
44
|
-
@command ||= config.keys.first
|
45
|
-
end
|
46
|
-
|
47
|
-
def patterns
|
48
|
-
@patterns ||= config.to_a.sort_by { |k, v| -k.size }.to_h
|
54
|
+
@command ||= config.keys.first.split(' ').first
|
49
55
|
end
|
50
56
|
|
51
57
|
def function_name
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Completely
|
2
|
+
class Pattern
|
3
|
+
attr_reader :text, :completions
|
4
|
+
|
5
|
+
def initialize(text, completions)
|
6
|
+
@text = text
|
7
|
+
@completions = completions || []
|
8
|
+
end
|
9
|
+
|
10
|
+
def length
|
11
|
+
@length ||= text.size
|
12
|
+
end
|
13
|
+
|
14
|
+
def empty?
|
15
|
+
completions.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
def words
|
19
|
+
@words ||= completions.reject { |w| w =~ /^<.*>$/ }
|
20
|
+
end
|
21
|
+
|
22
|
+
def actions
|
23
|
+
@actions ||= completions.filter_map do |word|
|
24
|
+
action = word[/^<(.+)>$/, 1]
|
25
|
+
"-A #{action}" if action
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def compgen
|
30
|
+
@comgen ||= compgen!
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def compgen!
|
36
|
+
result = []
|
37
|
+
result << %Q[#{actions.join ' '}] if actions.any?
|
38
|
+
result << %Q[-W "#{words.join ' '}"] if words.any?
|
39
|
+
result.any? ? result.join(' ') : nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/completely/template.erb
CHANGED
@@ -7,12 +7,9 @@
|
|
7
7
|
local cur=${COMP_WORDS[COMP_CWORD]}
|
8
8
|
|
9
9
|
case "$COMP_LINE" in
|
10
|
-
% patterns.each do |pattern
|
11
|
-
% next
|
12
|
-
|
13
|
-
% functions = words.filter_map { |w| func = w[/^<(.+)>$/, 1] ; "-A #{func}" if func }
|
14
|
-
% flags = functions.any? ? "#{functions.join ' '} -W" : "-W"
|
15
|
-
'<%= pattern %>'*) COMPREPLY=($(compgen <%= flags %> "<%= clean_words %>" -- "$cur")) ;;
|
10
|
+
% patterns.each do |pattern|
|
11
|
+
% next if pattern.empty?
|
12
|
+
'<%= pattern.text %>'*) COMPREPLY=($(compgen <%= pattern.compgen %> -- "$cur")) ;;
|
16
13
|
% end
|
17
14
|
esac
|
18
15
|
}
|
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.1.
|
4
|
+
version: 0.1.3
|
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-07-
|
11
|
+
date: 2021-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/completely/cli.rb
|
52
52
|
- lib/completely/command.rb
|
53
53
|
- lib/completely/completions.rb
|
54
|
+
- lib/completely/pattern.rb
|
54
55
|
- lib/completely/sample.yaml
|
55
56
|
- lib/completely/template.erb
|
56
57
|
- lib/completely/version.rb
|