]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shell-completion: Add completion for systemd-analyze critical-chain
authorNishal Kulkarni <nishalkulkarni@gmail.com>
Tue, 14 Dec 2021 08:43:13 +0000 (14:13 +0530)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 14 Dec 2021 09:27:49 +0000 (10:27 +0100)
systemd-analyze critical-chain accepts an optional unit argument,
however currently there's no shell-completion for it
This change provides unit name completion for both bash and zsh.

Closes: #20927
shell-completion/bash/systemd-analyze
shell-completion/zsh/_systemd-analyze

index f6dc972f031f234a6b452ed89bf72fc3724346bd..7a1104c0ad9700655d414bda4e53205b17c40ee2 100644 (file)
@@ -30,6 +30,11 @@ __get_machines() {
     machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; };
 }
 
+__get_units_all() {
+    systemctl list-units --no-legend --no-pager --plain --all | \
+        { while read -r a b c; do echo " $a"; done }
+}
+
 __get_services() {
     systemctl list-units --no-legend --no-pager --plain -t service --all $1 | \
         { while read -r a b c; do [[ $b == "loaded" ]]; echo " $a"; done }
@@ -111,6 +116,8 @@ _systemd_analyze() {
     elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then
         if [[ $cur = -* ]]; then
             comps='--help --version --system --user --fuzz --no-pager'
+        else
+            comps=$( __get_units_all )
         fi
 
     elif __contains_word "$verb" ${VERBS[DOT]}; then
index 9c33d73f981e36f0b9b3a56bbe9936290bae60a1..2ce8a3a088863a68a6339c1c204fe8e0d3864a01 100644 (file)
         _files -W '(/run/systemd/ /etc/systemd/ /usr/lib/systemd/)' -P 'systemd/'
     }
 
+(( $+functions[_systemd-analyze_critical-chain] )) ||
+    _systemd-analyze_critical-chain() {
+        local -a _units
+        systemctl list-units --no-legend --no-pager --plain --all |
+        while read -r a b c; do
+            _units+=($a)
+        done
+        compadd -a _units
+    }
+
 (( $+functions[_systemd-analyze_security] )) ||
     _systemd-analyze_security() {
         _sd_unit_files