From 6d1e7c3f0179b5e6e44aa1be2ba92dc38798191b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Old=C5=99ich=20Jedli=C4=8Dka?= Date: Wed, 19 Feb 2025 13:42:14 +0100 Subject: [PATCH] fix: handle spaces in bash completion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The spaces are not handled well in bash completion, the offered result needs to be escaped. Fix parsing the word list and add quotation around suggestions with spaces. See [here][1] for the details. [1]: https://stackoverflow.com/a/40944195/7080036 Signed-off-by: Oldřich Jedlička --- lib/completion-templates.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/completion-templates.ts b/lib/completion-templates.ts index c57ade373..ef87f4a15 100644 --- a/lib/completion-templates.ts +++ b/lib/completion-templates.ts @@ -13,9 +13,10 @@ _{{app_name}}_yargs_completions() args=("\${COMP_WORDS[@]}") # ask yargs to generate completions. - type_list=$({{app_path}} --get-yargs-completions "\${args[@]}") - - COMPREPLY=( $(compgen -W "\${type_list}" -- \${cur_word}) ) + # see https://stackoverflow.com/a/40944195/7080036 for the spaces-handling awk + mapfile -t type_list < <({{app_path}} --get-yargs-completions "\${args[@]}") + mapfile -t COMPREPLY < <(compgen -W "$( printf '%q ' "\${type_list[@]}" )" -- "\${cur_word}" | + awk '/ / { print "\\""$0"\\"" } /^[^ ]+$/ { print $0 }') # if no match was found, fall back to filename completion if [ \${#COMPREPLY[@]} -eq 0 ]; then