]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/systemd-analyze
man/systemd-sysext: list ephemeral/ephemeral-import in the list of options
[thirdparty/systemd.git] / shell-completion / bash / systemd-analyze
1 # shellcheck shell=bash
2 # systemd-analyze(1) completion -*- shell-script -*-
3 # SPDX-License-Identifier: LGPL-2.1-or-later
4 #
5 # This file is part of systemd.
6 #
7 # Copyright © 2010 Ran Benita
8 #
9 # systemd is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU Lesser General Public License as published by
11 # the Free Software Foundation; either version 2.1 of the License, or
12 # (at your option) any later version.
13 #
14 # systemd is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 # General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public License
20 # along with systemd; If not, see <https://www.gnu.org/licenses/>.
21
22 __contains_word () {
23 local w word=$1; shift
24 for w in "$@"; do
25 [[ $w = "$word" ]] && return
26 done
27 }
28
29 __get_machines() {
30 local a b
31 { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
32 { while read a b; do echo " $a"; done; } | \
33 sort -u
34 }
35
36 __get_units_all() {
37 systemctl list-units --no-legend --no-pager --plain --all $1 | \
38 { while read -r a b c; do echo " $a"; done }
39 }
40
41 __get_services() {
42 systemctl list-units --no-legend --no-pager --plain -t service --all $1 | \
43 { while read -r a b c; do [[ $b == "loaded" ]]; echo " $a"; done }
44 }
45
46 __get_syscall_sets() {
47 local line
48 systemd-analyze syscall-filter --no-pager | while IFS= read -r line; do
49 if [[ $line == @* ]]; then
50 printf '%s\n' "$line"
51 fi
52 done
53 }
54
55 __get_architectures() {
56 systemd-analyze --no-legend --no-pager architectures | { while read -r a b; do echo " $a"; done }
57 }
58
59 _systemd_analyze() {
60 local i verb comps mode
61 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
62
63 local -A OPTS=(
64 [STANDALONE]='-h --help --version --system --user --global --order --require --no-pager
65 --man=no --generators=yes -q --quiet'
66 [ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern --root'
67 )
68
69 local -A VERBS=(
70 [STANDALONE]='time blame unit-files unit-paths exit-status compare-versions calendar timestamp timespan pcrs srk has-tpm2 smbios11 chid'
71 [CRITICAL_CHAIN]='critical-chain'
72 [DOT]='dot'
73 [DUMP]='dump'
74 [VERIFY]='verify'
75 [SECCOMP_FILTER]='syscall-filter'
76 [CAT_CONFIG]='cat-config'
77 [SECURITY]='security'
78 [CONDITION]='condition'
79 [INSPECT_ELF]='inspect-elf'
80 [PLOT]='plot'
81 [ARCHITECTURES]='architectures'
82 [FDSTORE]='fdstore'
83 [CAPABILITY]='capability'
84 )
85
86 local CONFIGS='locale.conf systemd/bootchart.conf systemd/coredump.conf systemd/journald.conf
87 systemd/journal-remote.conf systemd/journal-upload.conf systemd/logind.conf
88 systemd/resolved.conf systemd/networkd.conf systemd/pstore.conf systemd/resolved.conf
89 systemd/sleep.conf systemd/system.conf systemd/timedated.conf
90 systemd/timesyncd.conf systemd/user.conf udev/udev.conf'
91
92 _init_completion || return
93
94 for ((i=0; i < COMP_CWORD; i++)); do
95 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
96 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
97 verb=${COMP_WORDS[i]}
98 break
99 fi
100 done
101
102 if __contains_word "--user" ${COMP_WORDS[*]}; then
103 mode=--user
104 else
105 mode=--system
106 fi
107
108 if __contains_word "$prev" ${OPTS[ARG]}; then
109 case $prev in
110 --host|-H)
111 comps=$(compgen -A hostname)
112 ;;
113 --machine|-M)
114 comps=$( __get_machines )
115 ;;
116 esac
117 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
118 return 0
119 fi
120
121 if [[ -z ${verb-} && $cur = -* ]]; then
122 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
123 return 0
124 fi
125
126 if [[ -z ${verb-} ]]; then
127 comps=${VERBS[*]}
128
129 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
130 if [[ $cur = -* ]]; then
131 comps='--help --version --system --user --global --no-pager'
132 fi
133
134 elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then
135 if [[ $cur = -* ]]; then
136 comps='--help --version --system --user --fuzz --no-pager'
137 else
138 comps=$( __get_units_all $mode )
139 fi
140
141 elif __contains_word "$verb" ${VERBS[DOT]}; then
142 if [[ $cur = -* ]]; then
143 comps='--help --version --system --user --global --from-pattern --to-pattern --order --require'
144 fi
145
146 elif __contains_word "$verb" ${VERBS[DUMP]}; then
147 if [[ $cur = -* ]]; then
148 comps='--help --version --system --user --no-pager'
149 else
150 comps=$( __get_units_all $mode )
151 fi
152
153 elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then
154 if [[ $cur = -* ]]; then
155 comps='--help --version --no-pager'
156 else
157 comps=$( __get_syscall_sets )
158 fi
159
160 elif __contains_word "$verb" ${VERBS[VERIFY]}; then
161 if [[ $cur = -* ]]; then
162 comps='--help --version --system --user --global --man=no --generators=yes --root --image --recursive-errors=no --recursive-errors=yes --recursive-errors=one'
163 else
164 comps=$( compgen -A file -- "$cur";
165 __get_units_all $mode )
166 compopt -o filenames
167 fi
168
169 elif __contains_word "$verb" ${VERBS[CAT_CONFIG]}; then
170 if [[ $cur = -* ]]; then
171 comps='--help --version --root --no-pager'
172 elif [[ -z $cur ]]; then
173 comps="$CONFIGS"
174 compopt -o filenames
175 else
176 comps="$CONFIGS $( compgen -A file -- "$cur" )"
177 compopt -o filenames
178 fi
179
180 elif __contains_word "$verb" ${VERBS[SECURITY]}; then
181 if [[ $cur = -* ]]; then
182 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'
183 elif ! __contains_word "--offline" ${COMP_WORDS[*]}; then
184 comps=$( __get_services $mode )
185 else
186 comps="$CONFIGS $( compgen -A file -- "$cur" )"
187 compopt -o filenames
188 fi
189
190 elif __contains_word "$verb" ${VERBS[CONDITION]}; then
191 if [[ $cur = -* ]]; then
192 comps='--help --version --system --user --global --no-pager --root --image'
193 elif [[ $prev = "-u" ]] || [[ $prev = "--unit" ]]; then
194 comps=$( __get_services $mode )
195 fi
196
197 elif __contains_word "$verb" ${VERBS[INSPECT_ELF]}; then
198 if [[ $cur = -* ]]; then
199 comps='--help --version --json=off --json=pretty --json=short'
200 else
201 comps=$( compgen -A file -- "$cur" )
202 compopt -o filenames
203 fi
204
205 elif __contains_word "$verb" ${VERBS[PLOT]}; then
206 if [[ $cur = -* ]]; then
207 comps='--help --version --system --user --global --no-pager --json=off --json=pretty --json=short --table --no-legend --scale-svg --detailed'
208 fi
209
210 elif __contains_word "$verb" ${VERBS[ARCHITECTURES]}; then
211 if [[ $cur = -* ]]; then
212 comps='--help --version --no-pager --json=off --json=pretty --json=short --no-legend'
213 else
214 comps=$( __get_architectures )
215 fi
216
217 elif __contains_word "$verb" ${VERBS[FDSTORE]}; then
218 if [[ $cur = -* ]]; then
219 comps='--help --version --system --user --global -H --host -M --machine --no-pager --json=off --json=pretty --json=short --root --image'
220 else
221 comps=$( __get_services $mode )
222 fi
223
224 elif __contains_word "$verb" ${VERBS[CAPABILITY]}; then
225 if [[ $cur = -* ]]; then
226 comps='--help --version --no-pager --json=off --json=pretty --json=short -m --mask'
227 fi
228 fi
229
230 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
231 return 0
232 }
233
234 complete -F _systemd_analyze systemd-analyze