Skip to content

Commit 38e334b

Browse files
author
Niklas Reisser
committed
Support compopt in completion functions
1 parent cf19980 commit 38e334b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

shtab/__init__.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,14 @@ def complete_bash(parser, root_prefix=None, preamble="", choice_functions=None):
421421
COMPREPLY=( $(compgen -W "${current_option_strings[*]}" -- "${completing_word}") )
422422
else
423423
# use choices & compgen
424-
COMPREPLY=( $(compgen -W "${current_action_choices}" -- "${completing_word}"; \\
425-
[ -n "${current_action_compgen}" ] \\
426-
&& "${current_action_compgen}" "${completing_word}") )
424+
# call current_action_compgen without a subshell to support compopt
425+
tmpfile="$(mktemp)"
426+
[ -n "${current_action_compgen}" ] && \\
427+
"${current_action_compgen}" "${completing_word}" > "$tmpfile"
428+
mapfile current_action_compreply < $tmpfile
429+
rm "$tmpfile"
430+
COMPREPLY=( $(compgen -W "${current_action_choices}" -- "${completing_word}") \\
431+
${current_action_compreply[@]} )
427432
fi
428433
429434
return 0

0 commit comments

Comments
 (0)