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 11_argc_completer () {
2- local words
2+ declare -a _argc_completer_words
33 _argc_completer_parse_line
44
55 export COMP_WORDBREAKS
66 while IFS=$' \n ' read -r line; do
77 COMPREPLY+=( " $line " )
8- done < <( argc --argc-compgen bash " " " ${words [@]} " 2> /dev/null)
8+ done < <( argc --argc-compgen bash " " " ${_argc_completer_words [@]} " 2> /dev/null)
99}
1010
1111_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
1413 line=" ${COMP_LINE: 0: $COMP_POINT } "
1514 len=" ${# line} "
15+
1616 for (( i= 0 ; i< len; i++ )) ; do
1717 char=" ${line: i: 1} "
1818 if [[ -n " $unbalance " ]]; then
@@ -24,8 +24,7 @@ _argc_completer_parse_line() {
2424 if [[ " $prev_char " == " \\ " ]]; then
2525 word=" $word$char "
2626 elif [[ -n " $word " ]]; then
27- words[$word_index ]=" $word "
28- word_index=$(( word_index+ 1 ))
27+ _argc_completer_words+=( " $word " )
2928 word=" "
3029 fi
3130 elif [[ " $char " == " '" || " $char " == ' "' ]]; then
@@ -40,7 +39,8 @@ _argc_completer_parse_line() {
4039 fi
4140 prev_char=" $char "
4241 done
43- words[$word_index ]=" $word "
42+
43+ _argc_completer_words+=( " $word " )
4444}
4545
4646complete -F _argc_completer -o nospace -o nosort \
Original file line number Diff line number Diff line change 11function _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 "
641 end
742
8- argc --argc-compgen fish " " $args
43+ set -a _argc_completer_words " $word "
944end
1045
1146
You can’t perform that action at this time.
0 commit comments