Skip to content

Commit 6a7ba97

Browse files
author
Niklas Reisser
committed
Support compopt in completion functions
1 parent 60a8525 commit 6a7ba97

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

shtab/__init__.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -421,10 +421,16 @@ 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+
# call current_action_compgen without a subshell to support compopt
424425
local IFS=$'\\n'
426+
tmpfile="$(mktemp)"
427+
[ -n "${current_action_compgen}" ] && \\
428+
"${current_action_compgen}" "${completing_word}" > "$tmpfile"
429+
mapfile current_action_compreply < "$tmpfile"
430+
rm "$tmpfile"
431+
425432
COMPREPLY=( $(compgen -W "${current_action_choices}" -- "${completing_word}") \\
426-
$([ -n "${current_action_compgen}" ] \\
427-
&& "${current_action_compgen}" "${completing_word}") )
433+
${current_action_compreply[@]} )
428434
fi
429435
430436
return 0

0 commit comments

Comments
 (0)