Skip to content

Commit

Permalink
Support compopt in completion functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Niklas Reisser committed Jun 8, 2022
1 parent cf19980 commit 38e334b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions shtab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,14 @@ def complete_bash(parser, root_prefix=None, preamble="", choice_functions=None):
COMPREPLY=( $(compgen -W "${current_option_strings[*]}" -- "${completing_word}") )
else
# use choices & compgen
COMPREPLY=( $(compgen -W "${current_action_choices}" -- "${completing_word}"; \\
[ -n "${current_action_compgen}" ] \\
&& "${current_action_compgen}" "${completing_word}") )
# call current_action_compgen without a subshell to support compopt
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}") \\
${current_action_compreply[@]} )
fi
return 0
Expand Down

0 comments on commit 38e334b

Please sign in to comment.