]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shell-completion: include units in 'verify' completions
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 24 Jul 2023 18:21:17 +0000 (20:21 +0200)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 24 Jul 2023 19:02:55 +0000 (20:02 +0100)
Resolves: #28500

shell-completion/bash/systemd-analyze

index 5edba7bf58c51983bfb362c3553cf8d2fa181443..8ecf99357155e7b10ca4c68ff40410b6715f55d5 100644 (file)
@@ -33,7 +33,7 @@ __get_machines() {
 }
 
 __get_units_all() {
-    systemctl list-units --no-legend --no-pager --plain --all | \
+    systemctl list-units --no-legend --no-pager --plain --all $1 | \
         { while read -r a b c; do echo " $a"; done }
 }
 
@@ -91,6 +91,12 @@ _systemd_analyze() {
         fi
     done
 
+    if __contains_word "--user" ${COMP_WORDS[*]}; then
+        mode=--user
+    else
+        mode=--system
+    fi
+
     if __contains_word "$prev" ${OPTS[ARG]}; then
         case $prev in
             --host|-H)
@@ -121,7 +127,7 @@ _systemd_analyze() {
         if [[ $cur = -* ]]; then
             comps='--help --version --system --user --fuzz --no-pager'
         else
-            comps=$( __get_units_all )
+            comps=$( __get_units_all $mode )
         fi
 
     elif __contains_word "$verb" ${VERBS[DOT]}; then
@@ -133,7 +139,7 @@ _systemd_analyze() {
         if [[ $cur = -* ]]; then
             comps='--help --version --system --user --no-pager'
         else
-            comps=$( __get_units_all )
+            comps=$( __get_units_all $mode )
         fi
 
     elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then
@@ -147,7 +153,8 @@ _systemd_analyze() {
         if [[ $cur = -* ]]; then
             comps='--help --version --system --user --global --man=no --generators=yes --root --image --recursive-errors=no --recursive-errors=yes --recursive-errors=one'
         else
-            comps=$( compgen -A file -- "$cur" )
+            comps=$( compgen -A file -- "$cur";
+                     __get_units_all $mode )
             compopt -o filenames
         fi
 
@@ -166,11 +173,6 @@ _systemd_analyze() {
         if [[ $cur = -* ]]; then
             comps='--help --version --no-pager --system --user -H --host -M --machine --offline --threshold --security-policy --json=off --json=pretty --json=short --root --image --profile=default --profile=nonetwork --profile=strict --profile=trusted'
         elif ! __contains_word "--offline" ${COMP_WORDS[*]}; then
-            if __contains_word "--user" ${COMP_WORDS[*]}; then
-                mode=--user
-            else
-                mode=--system
-            fi
             comps=$( __get_services $mode )
         else
             comps="$CONFIGS $( compgen -A file -- "$cur" )"
@@ -181,11 +183,6 @@ _systemd_analyze() {
         if [[ $cur = -* ]]; then
             comps='--help --version --system --user --global --no-pager --root --image'
         elif [[ $prev = "-u" ]] || [[ $prev = "--unit" ]]; then
-            if __contains_word "--user" ${COMP_WORDS[*]}; then
-                mode=--user
-            else
-                mode=--system
-            fi
             comps=$( __get_services $mode )
         fi