]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bash-completion: properly autocomplete escaped unit names
authorFrantisek Sumsal <frantisek@sumsal.cz>
Wed, 24 Apr 2019 12:22:44 +0000 (14:22 +0200)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Wed, 24 Apr 2019 16:03:15 +0000 (18:03 +0200)
shell-completion/bash/journalctl
shell-completion/bash/systemctl.in

index 52ed2e3bcb9c8c32dd42bb985df0069d4db898af..53ffaacdb55b66dbead1d50aefb321a0c69c4b88 100644 (file)
@@ -86,6 +86,7 @@ _journalctl() {
                 ;;
             --unit|-u)
                 comps=$(journalctl -F '_SYSTEMD_UNIT' 2>/dev/null)
+                compopt -o filenames
                 ;;
             --user-unit)
                 comps=$(journalctl -F '_SYSTEMD_USER_UNIT' 2>/dev/null)
@@ -100,7 +101,7 @@ _journalctl() {
                 return 0
                 ;;
         esac
-        COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
+        COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur") )
         return 0
     fi
 
index 8c86fed9746739eea94ff1a227f625ae4fc7735f..a827ed0d0e39cfa167bc8cbf9bf438b33ce0a1ec 100644 (file)
@@ -119,6 +119,7 @@ __get_machines() {
 
 _systemctl () {
     local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
+    local cur_orig=$cur
     local i verb comps mode
 
     local -A OPTS=(
@@ -221,6 +222,13 @@ _systemctl () {
         fi
     done
 
+    # When trying to match a unit name with certain special characters in its name (i.e
+    # foo\x2dbar:01) they get escaped by bash along the way, thus causing any possible
+    # match to fail. Let's unescape such characters in the verb we're trying to
+    # autocomplete to avoid this, however, use the original verb (cur_orig)
+    # during the final match (COMPREPLY)
+    cur="$(echo $cur | xargs echo)"
+
     if [[ -z $verb ]]; then
         comps="${VERBS[*]}"
 
@@ -306,7 +314,7 @@ _systemctl () {
                      | { while read -r a b; do echo " $a"; done; } )
     fi
 
-    COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur") )
+    COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur_orig") )
     return 0
 }