ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
4bff0a
From 8d1a8f099dbf79d0e18e055721228192a637a759 Mon Sep 17 00:00:00 2001
4bff0a
From: Yu Watanabe <watanabe.yu+github@gmail.com>
4bff0a
Date: Thu, 6 Dec 2018 18:51:56 +0100
4bff0a
Subject: [PATCH] bash-completion: analyze: support 'security'
4bff0a
4bff0a
(cherry picked from commit 83da42c3bf86e8787cfec2c7fb6ca379dfec3632)
4bff0a
4bff0a
Resolves: #1733395
4bff0a
---
4bff0a
 shell-completion/bash/systemd-analyze | 20 +++++++++++++++++++-
4bff0a
 1 file changed, 19 insertions(+), 1 deletion(-)
4bff0a
4bff0a
diff --git a/shell-completion/bash/systemd-analyze b/shell-completion/bash/systemd-analyze
4bff0a
index 21d0fcf1b8..b4fcfc6492 100644
4bff0a
--- a/shell-completion/bash/systemd-analyze
4bff0a
+++ b/shell-completion/bash/systemd-analyze
4bff0a
@@ -31,8 +31,13 @@ __get_machines() {
4bff0a
         machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
4bff0a
 }
4bff0a
 
4bff0a
+__get_services() {
4bff0a
+        systemctl list-units --no-legend --no-pager -t service --all $1 | \
4bff0a
+                { while read -r a b c; do [[ $b == "loaded" ]]; echo " $a"; done }
4bff0a
+}
4bff0a
+
4bff0a
 _systemd_analyze() {
4bff0a
-        local i verb comps
4bff0a
+        local i verb comps mode
4bff0a
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
4bff0a
 
4bff0a
         local -A OPTS=(
4bff0a
@@ -51,6 +56,7 @@ _systemd_analyze() {
4bff0a
                 [SECCOMP_FILTER]='syscall-filter'
4bff0a
                 [SERVICE_WATCHDOGS]='service-watchdogs'
4bff0a
                 [CAT_CONFIG]='cat-config'
4bff0a
+                [SECURITY]='security'
4bff0a
         )
4bff0a
 
4bff0a
         local CONFIGS='systemd/bootchart.conf systemd/coredump.conf systemd/journald.conf
4bff0a
@@ -149,6 +155,18 @@ _systemd_analyze() {
4bff0a
                         comps="$CONFIGS $( compgen -A file -- "$cur" )"
4bff0a
                         compopt -o filenames
4bff0a
                 fi
4bff0a
+
4bff0a
+        elif __contains_word "$verb" ${VERBS[SECURITY]}; then
4bff0a
+                if [[ $cur = -* ]]; then
4bff0a
+                        comps='--help --version --no-pager --system --user -H --host -M --machine'
4bff0a
+                else
4bff0a
+                        if __contains_word "--user" ${COMP_WORDS[*]}; then
4bff0a
+                                mode=--user
4bff0a
+                        else
4bff0a
+                                mode=--system
4bff0a
+                        fi
4bff0a
+                        comps=$( __get_services $mode )
4bff0a
+                fi
4bff0a
         fi
4bff0a
 
4bff0a
         COMPREPLY=( $(compgen -W '$comps' -- "$cur") )