bash completion now handles spaces correctly in both quoted and unquoted strings

Sat, 26 Oct 2019 15:38:50 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 26 Oct 2019 15:38:50 +0200
changeset 676
fb466ba2edc5
parent 675
a8117c4feaad
child 677
5a4002f8d258

bash completion now handles spaces correctly in both quoted and unquoted strings

scripts/dav-bash-completion.bash file | annotate | diff | comparison | revisions
--- a/scripts/dav-bash-completion.bash	Sat Oct 26 14:55:53 2019 +0200
+++ b/scripts/dav-bash-completion.bash	Sat Oct 26 15:38:50 2019 +0200
@@ -1,8 +1,23 @@
+dav_completion_build_args() {
+    local word
+    for i in "${!COMP_WORDS[@]}"; do
+        word="${COMP_WORDS[$i]}"
+        if [[ "$word" =~ ^\'|^\" ]]; then
+            printf "%s\0" "$word"
+        else
+            echo "$word" | xargs printf "%s"
+            printf "\0"
+        fi
+    done
+}
+
 dav_completion() {
+    local cmd
     local out
     local cmd_res
 
-    out="$(${COMP_WORDS[0]} complete $COMP_CWORD ${COMP_WORDS[@]})"
+    cmd="${COMP_WORDS[0]} complete $COMP_CWORD"
+    out=$(dav_completion_build_args | xargs -0 $cmd)
     cmd_res=$?
 
     if [[ $cmd_res -eq 10 ]]; then

mercurial