[systemd-devel] [PATCH] shell-completion: prevent mangling unit names (bash)

Eric Cook llua at gmx.com
Sat Jul 26 14:24:11 PDT 2014


This looks seems like it should work. I would appreciate it if you could trail run it.
My use of bash is limited and knowledge of it's completion system even more so.
---
 shell-completion/bash/systemctl.in | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/shell-completion/bash/systemctl.in b/shell-completion/bash/systemctl.in
index c5950cc..113694f 100644
--- a/shell-completion/bash/systemctl.in
+++ b/shell-completion/bash/systemctl.in
@@ -46,25 +46,25 @@ __filter_units_by_property () {
             <(__systemctl $mode show --property "$property" -- "${units[@]}")
         for ((i=0; $i < ${#units[*]}; i++)); do
                 if [[ "${props[i]}" = "$property=$value" ]]; then
-                        echo " ${units[i]}"
+                        printf '%q\n' " ${units[i]}"
                 fi
         done
 }
 
 __get_all_units      () { __systemctl $1 list-units --all \
-        | { while read -r a b; do echo " $a"; done; }; }
+        | { while read -r a b; do printf '%q\n' " $a"; done; }; }
 __get_active_units   () { __systemctl $1 list-units       \
-        | { while read -r a b; do echo " $a"; done; }; }
+        | { while read -r a b; do printf '%q\n' " $a"; done; }; }
 __get_startable_units () { __systemctl $1 list-units --all -t service,timer,socket,mount,automount,path,snapshot,swap \
-        | { while read -r a b c d; do [[ $c == "inactive" || $c == "failed" ]] && echo " $a"; done; }; }
+        | { while read -r a b c d; do [[ $c == "inactive" || $c == "failed" ]] && printf '%q\n' " $a"; done; }; }
 __get_failed_units   () { __systemctl $1 list-units       \
-        | { while read -r a b c d; do [[ $c == "failed"   ]] && echo " $a"; done; }; }
+        | { while read -r a b c d; do [[ $c == "failed"   ]] && printf '%q\n' " $a"; done; }; }
 __get_enabled_units  () { __systemctl $1 list-unit-files  \
-        | { while read -r a b c  ; do [[ $b == "enabled"  ]] && echo " $a"; done; }; }
+        | { while read -r a b c  ; do [[ $b == "enabled"  ]] && printf '%q\n' " $a"; done; }; }
 __get_disabled_units () { __systemctl $1 list-unit-files  \
-        | { while read -r a b c  ; do [[ $b == "disabled" ]] && echo " $a"; done; }; }
+        | { while read -r a b c  ; do [[ $b == "disabled" ]] && printf '%q\n' " $a"; done; }; }
 __get_masked_units   () { __systemctl $1 list-unit-files  \
-        | { while read -r a b c  ; do [[ $b == "masked"   ]] && echo " $a"; done; }; }
+        | { while read -r a b c  ; do [[ $b == "masked"   ]] && printf '%q\n' " $a"; done; }; }
 
 _systemctl () {
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
-- 
2.0.2



More information about the systemd-devel mailing list