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 +4 -4
- data/lib/completely/pattern.rb +17 -3
- data/lib/completely/templates/template.erb +22 -11
- data/lib/completely/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f63b147e4b4e7f96c823f6cced45b7a22a495a97318b04e105fd70ca6fe22358
|
|
4
|
+
data.tar.gz: d361744ab7255d15b6fed24fd662591a8b2fab91696a0e79490c988c18e0438d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ae9f53dc80b932438d14c2be2e430880e9ae0b326abb3db8fd2e9d20abb09cba18cc631a8f73cda1ccb6b070f0f23c2d5bddc436f3f4cd771f5a4fa278bc599b
|
|
7
|
+
data.tar.gz: 84966032ec9b12086c0722948e8da2070cdbc57a4d8aaba8f456581a0b88192a0ff7fba334631eae2c33d099ff23c48fbaa42bb141c9314d41083598d112d144
|
data/lib/completely/pattern.rb
CHANGED
|
@@ -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} #{
|
|
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
|
|
62
|
-
@
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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[*]}"
|
data/lib/completely/version.rb
CHANGED