From b5f9ff54f5a4fa212b734eb9ea842d86c0d64087 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Fri, 17 Jun 2022 13:58:10 +0100 Subject: [PATCH 1/3] fix #74 bash completion with space - vis. https://stackoverflow.com/questions/1146098/properly-handling-spaces-and-quotes-in-bash-completion --- shtab/__init__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/shtab/__init__.py b/shtab/__init__.py index 5467cfd..87ca026 100644 --- a/shtab/__init__.py +++ b/shtab/__init__.py @@ -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", "?"): @@ -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: @@ -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 From a8b9034d145dea7813c9d351e798112a4fb056d2 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Fri, 17 Jun 2022 14:08:01 +0100 Subject: [PATCH 2/3] update tests --- tests/test_shtab.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/test_shtab.py b/tests/test_shtab.py index fc8d09c..a7fbc19 100644 --- a/tests/test_shtab.py +++ b/tests/test_shtab.py @@ -197,11 +197,11 @@ def test_subparser_aliases(shell, caplog): if shell == "bash": shell = Bash(completion) shell.compgen('-W "${_shtab_test_subparsers[*]}"', "s", "sub") - shell.compgen('-W "$_shtab_test_pos_0_choices"', "s", "sub") + shell.compgen('-W "${_shtab_test_pos_0_choices[*]}"', "s", "sub") shell.compgen('-W "${_shtab_test_subparsers[*]}"', "x", "xsub") - shell.compgen('-W "$_shtab_test_pos_0_choices"', "x", "xsub") + shell.compgen('-W "${_shtab_test_pos_0_choices[*]}"', "x", "xsub") shell.compgen('-W "${_shtab_test_subparsers[*]}"', "y", "ysub") - shell.compgen('-W "$_shtab_test_pos_0_choices"', "y", "ysub") + shell.compgen('-W "${_shtab_test_pos_0_choices[*]}"', "y", "ysub") shell.test('"$($_shtab_test_sub_pos_0_COMPGEN o)" = "one"') shell.test('-z "$_shtab_test_COMPGEN"') @@ -245,9 +245,9 @@ def test_add_argument_to_positional(shell, caplog, capsys): if shell == "bash": shell = Bash(completion) shell.compgen('-W "${_shtab_test_subparsers[*]}"', "c", "completion") - shell.compgen('-W "$_shtab_test_pos_0_choices"', "c", "completion") - shell.compgen('-W "$_shtab_test_completion_pos_0_choices"', "ba", "bash") - shell.compgen('-W "$_shtab_test_completion_pos_0_choices"', "z", "zsh") + shell.compgen('-W "${_shtab_test_pos_0_choices[*]}"', "c", "completion") + shell.compgen('-W "${_shtab_test_completion_pos_0_choices[*]}"', "ba", "bash") + shell.compgen('-W "${_shtab_test_completion_pos_0_choices[*]}"', "z", "zsh") assert not caplog.record_tuples From b0b6d53aece9f0dd147da4fe34c87d8d96a13c08 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Fri, 17 Jun 2022 14:23:02 +0100 Subject: [PATCH 3/3] update pre-commit --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dee657d..65632af 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ default_language_version: python: python3 repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.3.0 hooks: - id: check-added-large-files - id: check-case-conflict @@ -39,7 +39,7 @@ repos: - flake8-string-format - flake8-type-annotations - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.930 + rev: v0.961 hooks: - id: mypy - repo: https://github.com/google/yapf