From a8de16b13d18153100fea3c4d10b410167538478 Mon Sep 17 00:00:00 2001 From: Frantisek Hrbata Date: Wed, 11 Dec 2024 11:09:01 +0100 Subject: [PATCH] fix(autocomplete): handle @-argument autocompletion in bash Enable @-argument completion only if '@' is not present in COMP_WORDBREAKS. When '@' is included, the @-argument is not considered part of the completion word, causing @-argument completion to function unreliably in bash. Signed-off-by: Frantisek Hrbata --- tools/export_utils/shell_types.py | 1 + tools/idf.py | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/export_utils/shell_types.py b/tools/export_utils/shell_types.py index d2e3460672..8918eb5d8e 100644 --- a/tools/export_utils/shell_types.py +++ b/tools/export_utils/shell_types.py @@ -126,6 +126,7 @@ class BashShell(UnixShell): then echo "$WARNING_MSG" fi + export IDF_PY_COMP_WORDBREAKS="$COMP_WORDBREAKS" fi """) diff --git a/tools/idf.py b/tools/idf.py index 14730df1e1..200a557d94 100755 --- a/tools/idf.py +++ b/tools/idf.py @@ -454,7 +454,13 @@ def init_cli(verbose_output: Optional[List]=None) -> Any: return None def shell_complete(self, ctx: click.core.Context, incomplete: str) -> List[CompletionItem]: - if incomplete.startswith('@'): + # Enable @-argument completion in bash only if @ is not present in + # COMP_WORDBREAKS. When @ is included, the @-argument is not considered + # part of the completion word, causing @-argument completion to function + # unreliably in bash. + complete_file = ('bash' not in os.environ.get('_IDF.PY_COMPLETE', '') or + '@' not in os.environ.get('IDF_PY_COMP_WORDBREAKS', '')) + if incomplete.startswith('@') and complete_file: path_prefix = incomplete[1:] candidates = glob.glob(path_prefix + '*') result = [CompletionItem(f'@{c}') for c in candidates]