Skip to content

Commit

Permalink
fix #74 bash completion with space
Browse files Browse the repository at this point in the history
  • Loading branch information
casperdcl committed Jun 17, 2022
1 parent cf19980 commit 1f9af57
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions shtab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ def recurse(parser, prefix):
this_positional_choices.append(str(choice))

if this_positional_choices:
choices.append(u"{}_pos_{}_choices='{}'".format(
prefix, i, " ".join(this_positional_choices)))
choices.append(u"{}_pos_{}_choices=('{}')".format(
prefix, i, "' '".join(this_positional_choices)))

# skip default `nargs` values
if positional.nargs not in (None, "1", "?"):
Expand Down Expand Up @@ -266,8 +266,8 @@ def recurse(parser, prefix):
this_optional_choices.append(str(choice))

if this_optional_choices:
choices.append(u"{}_{}_choices='{}'".format(
prefix, wordify(option_string), " ".join(this_optional_choices)))
choices.append(u"{}_{}_choices=('{}')".format(
prefix, wordify(option_string), "' '".join(this_optional_choices)))

# Check for nargs.
if optional.nargs is not None and optional.nargs != 1:
Expand Down Expand Up @@ -421,8 +421,9 @@ 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}" ] \\
local IFS=$'\n'
COMPREPLY=( $(compgen -W "${current_action_choices}" -- "${completing_word}") \\
$([ -n "${current_action_compgen}" ] \\
&& "${current_action_compgen}" "${completing_word}") )
fi
Expand Down

0 comments on commit 1f9af57

Please sign in to comment.