File tree Expand file tree Collapse file tree 2 files changed +47
-12
lines changed Expand file tree Collapse file tree 2 files changed +47
-12
lines changed Original file line number Diff line number Diff line change 1
1
_argc_completer () {
2
- local words
2
+ declare -a _argc_completer_words
3
3
_argc_completer_parse_line
4
4
5
5
export COMP_WORDBREAKS
6
6
while IFS=$' \n ' read -r line; do
7
7
COMPREPLY+=( " $line " )
8
- done < <( argc --argc-compgen bash " " " ${words [@]} " 2> /dev/null)
8
+ done < <( argc --argc-compgen bash " " " ${_argc_completer_words [@]} " 2> /dev/null)
9
9
}
10
10
11
11
_argc_completer_parse_line () {
12
- local line len i char prev_char word unbalance word_index
13
- word_index=0
12
+ local line len i char prev_char word unbalance
14
13
line=" ${COMP_LINE: 0: $COMP_POINT } "
15
14
len=" ${# line} "
15
+
16
16
for (( i= 0 ; i< len; i++ )) ; do
17
17
char=" ${line: i: 1} "
18
18
if [[ -n " $unbalance " ]]; then
@@ -24,8 +24,7 @@ _argc_completer_parse_line() {
24
24
if [[ " $prev_char " == " \\ " ]]; then
25
25
word=" $word$char "
26
26
elif [[ -n " $word " ]]; then
27
- words[$word_index ]=" $word "
28
- word_index=$(( word_index+ 1 ))
27
+ _argc_completer_words+=( " $word " )
29
28
word=" "
30
29
fi
31
30
elif [[ " $char " == " '" || " $char " == ' "' ]]; then
@@ -40,7 +39,8 @@ _argc_completer_parse_line() {
40
39
fi
41
40
prev_char=" $char "
42
41
done
43
- words[$word_index ]=" $word "
42
+
43
+ _argc_completer_words+=( " $word " )
44
44
}
45
45
46
46
complete -F _argc_completer -o nospace -o nosort \
Original file line number Diff line number Diff line change 1
1
function _argc_completer
2
- set -l args (commandline -o )
3
- set -l cur (commandline -t )
4
- if [ ! " $cur " ]
5
- set -a args ' '
2
+ set -g _argc_completer_words
3
+ _argc_completer_parse_line
4
+
5
+ argc --argc-compgen fish " " $_ argc_completer_words
6
+ end
7
+
8
+ function _argc_completer_parse_line
9
+ set -l line (commandline -cp )
10
+ set -l word ' '
11
+ set -l unbalance ' '
12
+ set -l prev_char ' '
13
+
14
+ for i in (seq (string length -- $line ))
15
+ set -l char (string sub -s $i -l 1 -- $line )
16
+
17
+ if test -n " $unbalance "
18
+ set word " $word$char "
19
+ if test " $unbalance " = " $char "
20
+ set unbalance ' '
21
+ end
22
+ else if test " $char " = ' '
23
+ if test " $prev_char " = ' \\'
24
+ set word "$word$char "
25
+ else if test -n "$word "
26
+ set -a _argc_completer_words "$word "
27
+ set word ' '
28
+ end
29
+ else if test "$char " = "' " -o " $char " = '" '
30
+ set word "$word$char "
31
+ set unbalance "$char "
32
+ else if test "$char " = ' \\ '
33
+ if test "$prev_char " = ' \\ '
34
+ set word "$word$char "
35
+ end
36
+ else
37
+ set word "$word$char "
38
+ end
39
+
40
+ set prev_char "$char "
6
41
end
7
42
8
- argc --argc-compgen fish " " $args
43
+ set -a _argc_completer_words " $word "
9
44
end
10
45
11
46
You can’t perform that action at this time.
0 commit comments