Skip to content

Commit e61846b

Browse files
authored
Merge pull request #22 from meeuw/update-py-bash-completion
update bash_completion.py to 2.6
2 parents 7582c9d + ccb28b4 commit e61846b

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

ptrepl/vendor/bash_completion.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import functools
1515
import subprocess
1616

17-
__version__ = '0.2.5'
17+
__version__ = '0.2.6'
1818

1919

2020
@functools.lru_cache(1)
@@ -221,22 +221,39 @@ def _bash_quote_paths(paths, start, end):
221221
complete -p {cmd} 2> /dev/null || echo "-F _minimal"
222222
}}
223223
224+
function getarg {{
225+
find=$1
226+
shift 1
227+
prev=""
228+
for i in $* ; do
229+
if [ "$prev" = "$find" ] ; then
230+
echo $i
231+
fi
232+
prev=$i
233+
done
234+
}}
235+
224236
_complete_stmt=$(_get_complete_statement)
225237
if echo "$_complete_stmt" | grep --quiet -e "_minimal"
226238
then
227239
declare -f _completion_loader > /dev/null && _completion_loader {cmd}
228240
_complete_stmt=$(_get_complete_statement)
229241
fi
230242
231-
_func=$(echo "$_complete_stmt" | grep -o -e '-F \w\+' | cut -d ' ' -f 2)
232-
declare -f "$_func" > /dev/null || exit 1
243+
# Is -C (subshell) or -F (function) completion used?
244+
if [[ $_complete_stmt =~ "-C" ]] ; then
245+
_func=$(eval getarg "-C" $_complete_stmt)
246+
else
247+
_func=$(eval getarg "-F" $_complete_stmt)
248+
declare -f "$_func" > /dev/null || exit 1
249+
fi
233250
234251
echo "$_complete_stmt"
235-
COMP_WORDS=({line})
236-
COMP_LINE={comp_line}
237-
COMP_POINT=${{#COMP_LINE}}
238-
COMP_COUNT={end}
239-
COMP_CWORD={n}
252+
export COMP_WORDS=({line})
253+
export COMP_LINE={comp_line}
254+
export COMP_POINT=${{#COMP_LINE}}
255+
export COMP_COUNT={end}
256+
export COMP_CWORD={n}
240257
$_func {cmd} {prefix} {prev}
241258
242259
# print out completions, right-stripped if they contain no internal spaces

0 commit comments

Comments
 (0)