1 # shellcheck shell=bash
2 # systemd-analyze(1) completion -*- shell-script -*-
3 # SPDX-License-Identifier: LGPL-2.1-or-later
5 # This file is part of systemd.
7 # Copyright © 2010 Ran Benita
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.
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.
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/>.
23 local w word=$1; shift
25 [[ $w = "$word" ]] && return
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; } | \
37 systemctl list-units --no-legend --no-pager --plain --all $1 | \
38 { while read -r a b c; do echo " $a"; done }
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 }
46 __get_syscall_sets() {
48 systemd-analyze syscall-filter --no-pager | while IFS= read -r line; do
49 if [[ $line == @* ]]; then
55 __get_architectures() {
56 systemd-analyze --no-legend --no-pager architectures | { while read -r a b; do echo " $a"; done }
60 local i verb comps mode
61 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
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'
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'
75 [SECCOMP_FILTER]='syscall-filter'
76 [CAT_CONFIG]='cat-config'
78 [CONDITION]='condition'
79 [INSPECT_ELF]='inspect-elf'
81 [ARCHITECTURES]='architectures'
83 [CAPABILITY]='capability'
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'
92 _init_completion || return
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
102 if __contains_word "--user" ${COMP_WORDS[*]}; then
108 if __contains_word "$prev" ${OPTS[ARG]}; then
111 comps=$(compgen -A hostname)
114 comps=$( __get_machines )
117 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
121 if [[ -z ${verb-} && $cur = -* ]]; then
122 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
126 if [[ -z ${verb-} ]]; then
129 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
130 if [[ $cur = -* ]]; then
131 comps='--help --version --system --user --global --no-pager'
134 elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then
135 if [[ $cur = -* ]]; then
136 comps='--help --version --system --user --fuzz --no-pager'
138 comps=$( __get_units_all $mode )
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'
146 elif __contains_word "$verb" ${VERBS[DUMP]}; then
147 if [[ $cur = -* ]]; then
148 comps='--help --version --system --user --no-pager'
150 comps=$( __get_units_all $mode )
153 elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then
154 if [[ $cur = -* ]]; then
155 comps='--help --version --no-pager'
157 comps=$( __get_syscall_sets )
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'
164 comps=$( compgen -A file -- "$cur";
165 __get_units_all $mode )
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
176 comps="$CONFIGS $( compgen -A file -- "$cur" )"
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 )
186 comps="$CONFIGS $( compgen -A file -- "$cur" )"
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 )
197 elif __contains_word "$verb" ${VERBS[INSPECT_ELF]}; then
198 if [[ $cur = -* ]]; then
199 comps='--help --version --json=off --json=pretty --json=short'
201 comps=$( compgen -A file -- "$cur" )
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'
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'
214 comps=$( __get_architectures )
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'
221 comps=$( __get_services $mode )
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'
230 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
234 complete -F _systemd_analyze systemd-analyze