completely 0.7.4 → 0.8.0.rc1

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: e03a96457b69bced5091cb3a335f60da59ed7629d836f985f6bef54e89f8d827
4
- data.tar.gz: fb9fdf6333328841bb45fd65a6428571934602f13d5c7f1b555bc6dc7120c224
3
+ metadata.gz: f63b147e4b4e7f96c823f6cced45b7a22a495a97318b04e105fd70ca6fe22358
4
+ data.tar.gz: d361744ab7255d15b6fed24fd662591a8b2fab91696a0e79490c988c18e0438d
5
5
  SHA512:
6
- metadata.gz: b085523a2bb092c928fd6ff908baef5e5e1c0c68775688ea5e1a31ba77e19c09acfd17c19395f513a44eae88c9ab36cb28784e6ddae1afda46053d8de3f79981
7
- data.tar.gz: '0835d18cf9bf62f98c794368d39173263890856fe15ee601455b272ac5944a311a7bfee3e9eb6b8aa9ea215c2cd4713b7b5eb5e9c2c8cfb89764149064b41273'
6
+ metadata.gz: ae9f53dc80b932438d14c2be2e430880e9ae0b326abb3db8fd2e9d20abb09cba18cc631a8f73cda1ccb6b070f0f23c2d5bddc436f3f4cd771f5a4fa278bc599b
7
+ data.tar.gz: 84966032ec9b12086c0722948e8da2070cdbc57a4d8aaba8f456581a0b88192a0ff7fba334631eae2c33d099ff23c48fbaa42bb141c9314d41083598d112d144
@@ -1,5 +1,7 @@
1
1
  module Completely
2
2
  class Pattern
3
+ DYNAMIC_WORD_PREFIX = '__completely_dynamic__'
4
+
3
5
  attr_reader :text, :completions, :function_name
4
6
 
5
7
  def initialize(text, completions, function_name)
@@ -54,12 +56,24 @@ module Completely
54
56
  def compgen!
55
57
  result = []
56
58
  result << actions.join(' ').to_s if actions.any?
57
- result << %[-W "$(#{function_name} #{quoted_words.join ' '})"] if words.any?
59
+ result << %[-W "$(#{function_name} #{serialized_words.join ' '})"] if words.any?
58
60
  result.any? ? result.join(' ') : nil
59
61
  end
60
62
 
61
- def quoted_words
62
- @quoted_words ||= words.map { |word| %("#{escape_for_double_quotes word}") }
63
+ def serialized_words
64
+ @serialized_words ||= words.map { |word| serialize_word(word) }
65
+ end
66
+
67
+ def serialize_word(word)
68
+ if dynamic_word?(word)
69
+ return %("#{DYNAMIC_WORD_PREFIX}#{escape_for_double_quotes word}")
70
+ end
71
+
72
+ %("#{escape_for_double_quotes word}")
73
+ end
74
+
75
+ def dynamic_word?(word)
76
+ word.match?(/\A\$\(.+\)\z/)
63
77
  end
64
78
 
65
79
  def escape_for_double_quotes(word)
@@ -9,6 +9,7 @@
9
9
  local cur=${COMP_WORDS[COMP_CWORD]}
10
10
  local result=()
11
11
  local want_options=0
12
+ local dynamic_prefix="<%= Completely::Pattern::DYNAMIC_WORD_PREFIX %>"
12
13
 
13
14
  # words the user already typed (excluding the command itself)
14
15
  local used=()
@@ -20,19 +21,29 @@
20
21
  # Completing a non-option: drop options and already-used words.
21
22
  [[ "${cur:0:1}" == "-" ]] && want_options=1
22
23
  for word in "${words[@]}"; do
23
- if ((!want_options)); then
24
- [[ "${word:0:1}" == "-" ]] && continue
25
-
26
- for u in "${used[@]}"; do
27
- if [[ "$u" == "$word" ]]; then
28
- continue 2
29
- fi
30
- done
24
+ local candidates=("$word")
25
+ if [[ "$word" == "$dynamic_prefix"* ]]; then
26
+ word="${word#"$dynamic_prefix"}"
27
+ word="${word//$'\r'/ }"
28
+ word="${word//$'\n'/ }"
29
+ read -r -a candidates <<<"$word"
31
30
  fi
32
31
 
33
- # compgen -W expects shell-escaped words in one space-delimited string.
34
- printf -v word '%q' "$word"
35
- result+=("$word")
32
+ for candidate in "${candidates[@]}"; do
33
+ if ((!want_options)); then
34
+ [[ "${candidate:0:1}" == "-" ]] && continue
35
+
36
+ for u in "${used[@]}"; do
37
+ if [[ "$u" == "$candidate" ]]; then
38
+ continue 2
39
+ fi
40
+ done
41
+ fi
42
+
43
+ # compgen -W expects shell-escaped words in one space-delimited string.
44
+ printf -v candidate '%q' "$candidate"
45
+ result+=("$candidate")
46
+ done
36
47
  done
37
48
 
38
49
  echo "${result[*]}"
@@ -1,3 +1,3 @@
1
1
  module Completely
2
- VERSION = '0.7.4'
2
+ VERSION = '0.8.0.rc1'
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.7.4
4
+ version: 0.8.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit