Skip to content

Commit 83b7788

Browse files
oldiumBenjamin E. Coe
andauthored
fix: handle spaces in bash completion (#2452)
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 <[email protected]> Co-authored-by: Benjamin E. Coe <[email protected]>
1 parent 576236e commit 83b7788

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎lib/completion-templates.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ _{{app_name}}_yargs_completions()
1313
args=("\${COMP_WORDS[@]}")
1414
1515
# ask yargs to generate completions.
16-
type_list=$({{app_path}} --get-yargs-completions "\${args[@]}")
17-
18-
COMPREPLY=( $(compgen -W "\${type_list}" -- \${cur_word}) )
16+
# see https://stackoverflow.com/a/40944195/7080036 for the spaces-handling awk
17+
mapfile -t type_list < <({{app_path}} --get-yargs-completions "\${args[@]}")
18+
mapfile -t COMPREPLY < <(compgen -W "$( printf '%q ' "\${type_list[@]}" )" -- "\${cur_word}" |
19+
awk '/ / { print "\\""$0"\\"" } /^[^ ]+$/ { print $0 }')
1920
2021
# if no match was found, fall back to filename completion
2122
if [ \${#COMPREPLY[@]} -eq 0 ]; then

0 commit comments

Comments
 (0)