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 <frantisek.hrbata@espressif.com>
This commit is contained in:
Frantisek Hrbata
2024-12-11 11:09:01 +01:00
parent 96e627d9a1
commit a8de16b13d
2 changed files with 8 additions and 1 deletions

View File

@@ -126,6 +126,7 @@ class BashShell(UnixShell):
then then
echo "$WARNING_MSG" echo "$WARNING_MSG"
fi fi
export IDF_PY_COMP_WORDBREAKS="$COMP_WORDBREAKS"
fi fi
""") """)

View File

@@ -454,7 +454,13 @@ def init_cli(verbose_output: Optional[List]=None) -> Any:
return None return None
def shell_complete(self, ctx: click.core.Context, incomplete: str) -> List[CompletionItem]: 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:] path_prefix = incomplete[1:]
candidates = glob.glob(path_prefix + '*') candidates = glob.glob(path_prefix + '*')
result = [CompletionItem(f'@{c}') for c in candidates] result = [CompletionItem(f'@{c}') for c in candidates]