completely 0.1.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba5123d5b0bf95ed7ea2140188a6079e0510456a754d5fd93830df1382862274
4
- data.tar.gz: 0f98b90e1515d753b94817932916aad966b8b3f81ede79f1bbb40a898b82662e
3
+ metadata.gz: c09f951fc28b18f24c2c28fd7c80a15b3731aa07456145ab905c63c2b0dc9634
4
+ data.tar.gz: a9a25173ab3358e7eea42fe38552cbced8c6602bf5a0e9e6c414555420ae7af6
5
5
  SHA512:
6
- metadata.gz: e3618affd00e4a624b288ae7c37fd0d857fd9cf0672d6bcc8c558eb7870e2e3001e86a1c6997bc177def3b245bdc1142287539d99423dc175f6e208a9bf8a3b9
7
- data.tar.gz: a34bc567cbf492e437168afeb0a509f392eb1600a49622136d50728a936c024ad90e757d3a3ede18b0b7204302b09e08567054c73f75ea03fd3cdea9d39074e3
6
+ metadata.gz: b6edd13c5a0084485b7cb7114c45cf30d8c144075a3791aa51a8f5e7fc71df825cb03cb4786bc8fb3832f7bc1a46f06876614493184c4602d7e2e0dfbd3d4854
7
+ data.tar.gz: f8eb6cb08636c4281b50d7542d3c92fc8c6914e10597605f48e29ae342b6fb8cd31fff84de9e81dc0a7011bd5e963469c11fe025719e537238883d0a5812b5d9
data/README.md CHANGED
@@ -100,7 +100,7 @@ You may have noticed that the sample file contains two special entries:
100
100
  - `<directory>`
101
101
 
102
102
  These patterns will add the list of files and directories
103
- (when `<file>` is used) or just directories (when `<directory` is used) to
103
+ (when `<file>` is used) or just directories (when `<directory>` is used) to
104
104
  the list of suggestions.
105
105
 
106
106
  For those interested in the technical details, any word between `<...>` will
@@ -136,6 +136,10 @@ completions = Completely::Completions.new input
136
136
 
137
137
  # Generate the script
138
138
  puts completions.script
139
+
140
+ # Or, generate a function that echos the script
141
+ puts completions.wrapper_function
142
+ puts completions.wrapper_function "custom_function_name"
139
143
  ```
140
144
 
141
145
 
@@ -5,7 +5,7 @@ module Completely
5
5
 
6
6
  usage "completely new [CONFIG_PATH]"
7
7
  usage "completely preview [CONFIG_PATH --function NAME]"
8
- usage "completely generate [CONFIG_PATH OUTPUT_PATH --function NAME]"
8
+ usage "completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]"
9
9
  usage "completely (-h|--help|--version)"
10
10
 
11
11
  command "new", "Create a new sample YAML configuration file"
@@ -13,16 +13,18 @@ module Completely
13
13
  command "generate", "Generate the bash completion script to a file"
14
14
 
15
15
  option "-f --function NAME", "Modify the name of the function in the generated script"
16
+ option "-w --wrap NAME", "Wrap the completion script inside a function that echos the script. This is useful if you wish to embed it directly in your script"
16
17
 
17
18
  param "CONFIG_PATH", "Path to the YAML configuration file"
18
19
  param "OUTPUT_PATH", "Path to the output bash script"
19
20
 
20
21
  example "completely new"
21
22
  example "completely new input.yaml"
22
- example "completely preview --function my_completions"
23
+ example "completely preview --function _my_completions"
23
24
  example "completely generate"
24
25
  example "completely generate input.yaml"
25
- example "completely generate input.yaml output.sh -f my_completions"
26
+ example "completely generate input.yaml output.sh -f _my_completions"
27
+ example "completely generate -w give_comps -f my_completions"
26
28
 
27
29
  def new_command
28
30
  if File.exist? config_path
@@ -38,7 +40,9 @@ module Completely
38
40
  end
39
41
 
40
42
  def generate_command
41
- File.write output_path, script
43
+ wrap = args['--wrap']
44
+ output = wrap ? wrapper_function(wrap) : script
45
+ File.write output_path, output
42
46
  say "Saved !txtpur!#{output_path}"
43
47
  end
44
48
 
@@ -64,6 +68,10 @@ module Completely
64
68
  @script ||= completions.script
65
69
  end
66
70
 
71
+ def wrapper_function(wrapper_name)
72
+ completions.wrapper_function wrapper_name
73
+ end
74
+
67
75
  def completions
68
76
  @completions ||= Completions.load(config_path, function_name: args['--function'])
69
77
  end
@@ -19,6 +19,17 @@ module Completely
19
19
  ERB.new(template, trim_mode: '%-').result(binding)
20
20
  end
21
21
 
22
+ def wrapper_function(name = nil)
23
+ name ||= "send_completions"
24
+
25
+ script_lines = script.split("\n").map do |line|
26
+ clean_line = line.gsub("'") { "\\'" }
27
+ %Q[ echo $'#{clean_line}']
28
+ end.join("\n")
29
+
30
+ "#{name}() {\n#{script_lines}\n}"
31
+ end
32
+
22
33
  private
23
34
 
24
35
  def template_path
@@ -6,7 +6,7 @@
6
6
  <%= function_name %>() {
7
7
  local cur=${COMP_WORDS[COMP_CWORD]}
8
8
 
9
- case "$COMP_LINE" in
9
+ case "$COMP_LINE" in
10
10
  % patterns.each do |pattern, words|
11
11
  % next unless words
12
12
  % clean_words = words.reject { |w| w =~ /^<.*>$/ }.join " "
@@ -1,3 +1,3 @@
1
1
  module Completely
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: completely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit