diff --git a/shtab/__init__.py b/shtab/__init__.py index 87ca026..ac3fbee 100644 --- a/shtab/__init__.py +++ b/shtab/__init__.py @@ -421,10 +421,16 @@ def complete_bash(parser, root_prefix=None, preamble="", choice_functions=None): COMPREPLY=( $(compgen -W "${current_option_strings[*]}" -- "${completing_word}") ) else # use choices & compgen + # call current_action_compgen without a subshell to support compopt local IFS=$'\\n' + tmpfile="$(mktemp)" + [ -n "${current_action_compgen}" ] && \\ + "${current_action_compgen}" "${completing_word}" > "$tmpfile" + mapfile current_action_compreply < "$tmpfile" + rm "$tmpfile" + COMPREPLY=( $(compgen -W "${current_action_choices}" -- "${completing_word}") \\ - $([ -n "${current_action_compgen}" ] \\ - && "${current_action_compgen}" "${completing_word}") ) + ${current_action_compreply[@]} ) fi return 0