From b0f2e4ab1d540834f375a87e0671bd9d0a763da9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Fri, 28 Jul 2023 21:52:19 +0300 Subject: [PATCH] Match bash current word exactly instead of as regex Matching as regex does not seem correct for these cases to me offhand. --- shtab/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shtab/__init__.py b/shtab/__init__.py index 2089de1..9a1da2a 100644 --- a/shtab/__init__.py +++ b/shtab/__init__.py @@ -394,13 +394,13 @@ def complete_bash(parser, root_prefix=None, preamble="", choice_functions=None): while [ $word_index -ne $COMP_CWORD ]; do local this_word="${COMP_WORDS[$word_index]}" - if [[ -n $sub_parsers && " ${sub_parsers[@]} " =~ " ${this_word} " ]]; then + if [[ -n $sub_parsers && " ${sub_parsers[@]} " == *" ${this_word} "* ]]; then # valid subcommand: add it to the prefix & reset the current action prefix="${prefix}_$(_shtab_replace_nonword $this_word)" _set_parser_defaults fi - if [[ " ${current_option_strings[@]} " =~ " ${this_word} " ]]; then + if [[ " ${current_option_strings[@]} " == *" ${this_word} "* ]]; then # a new action should be acquired (due to recognised option string or # no more input expected from current action); # the next positional action can fill in here