completely 0.1.3 → 0.2.0

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: e8b8cc9f26134e125f8d8ec1d24081bdd3c22217e916c9233b00b471381fadc6
4
- data.tar.gz: a161403557ba173302233a3f4c3a4b61b084157f648709b1c79627f48aac9c97
3
+ metadata.gz: 54ee6b84395ab00c6d0fdde61065b9843b178947a7569cea41cead7b149ef55b
4
+ data.tar.gz: 3dd72641e530c42b0642b5861f1b38c219b5931846ed2da7fb20648563954094
5
5
  SHA512:
6
- metadata.gz: 22d3aa7b9db836ed7977d8888f46412184ea05d8de95632476275b6a33905308556d240014e816a01c47d9d56a35dd3181aec02eec149996587803db3fc47699
7
- data.tar.gz: a0796eedf218a01c54ba31cdb63a7a9db747ec83eb5f37726fcd67e9b201291b3f6856b28a0323310bbaf613dec3f710a2d667b6ee02751d38d391e20c079287
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
- - --argument
40
- - --param
41
- - command
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
- You may have noticed that the sample file contains two special entries:
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
- - `<file>`
103
- - `<directory>`
107
+ ```yaml
108
+ pattern:
109
+ - <file>
110
+ - <directory>
111
+ ```
104
112
 
105
- These patterns will add the list of files and directories
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 add any of the below keywords to add additional suggestions:
117
+ You may use any of the below keywords to add additional suggestions:
110
118
 
111
- | Keyword | Meaning
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://github.com/DannyBen/bashly
207
+ [bashly]: https://bashly.dannyb.co/
@@ -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
@@ -26,8 +26,16 @@ module Completely
26
26
  end
27
27
  end
28
28
 
29
+ def prefix
30
+ text.split(' ')[0]
31
+ end
32
+
33
+ def text_without_prefix
34
+ text.split(' ')[1..-1].join ' '
35
+ end
36
+
29
37
  def compgen
30
- @comgen ||= compgen!
38
+ @compgen ||= compgen!
31
39
  end
32
40
 
33
41
  private
@@ -9,6 +9,7 @@ mygit status:
9
9
  - --help
10
10
  - --verbose
11
11
  - --branch
12
+ - $(git branch 2> /dev/null)
12
13
 
13
14
  mygit init:
14
15
  - --bare
@@ -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 "$COMP_LINE" in
10
+ case "$comp_line" in
10
11
  % patterns.each do |pattern|
11
12
  % next if pattern.empty?
12
- '<%= pattern.text %>'*) COMPREPLY=($(compgen <%= pattern.compgen %> -- "$cur")) ;;
13
+ '<%= pattern.text_without_prefix %>'*) COMPREPLY=($(compgen <%= pattern.compgen %> -- "$cur")) ;;
13
14
  % end
14
15
  esac
15
16
  }
@@ -1,3 +1,3 @@
1
1
  module Completely
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
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.3
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-07-21 00:00:00.000000000 Z
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.16
77
+ rubygems_version: 3.2.25
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Bash Completions Generator