1 # systemd-analyze(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1-or-later
4 # This file is part of systemd.
6 # Copyright © 2010 Ran Benita
8 # systemd is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation; either version 2.1 of the License, or
11 # (at your option) any later version.
13 # systemd is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with systemd; If not, see <https://www.gnu.org/licenses/>.
22 local w word=$1; shift
24 [[ $w = "$word" ]] && return
30 { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
31 { while read a b; do echo " $a"; done; } | \
36 systemctl list-units --no-legend --no-pager --plain --all $1 | \
37 { while read -r a b c; do echo " $a"; done }
41 systemctl list-units --no-legend --no-pager --plain -t service --all $1 | \
42 { while read -r a b c; do [[ $b == "loaded" ]]; echo " $a"; done }
45 __get_syscall_sets() {
47 systemd-analyze syscall-filter --no-pager | while IFS= read -r line; do
48 if [[ $line == @* ]]; then
54 __get_architectures() {
55 systemd-analyze --no-legend --no-pager architectures | { while read -r a b; do echo " $a"; done }
59 local i verb comps mode
60 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
63 [STANDALONE]='-h --help --version --system --user --global --order --require --no-pager
64 --man=no --generators=yes -q --quiet'
65 [ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern --root'
69 [STANDALONE]='time blame unit-paths exit-status calendar timestamp timespan'
70 [CRITICAL_CHAIN]='critical-chain'
74 [SECCOMP_FILTER]='syscall-filter'
75 [CAT_CONFIG]='cat-config'
77 [CONDITION]='condition'
78 [INSPECT_ELF]='inspect-elf'
80 [ARCHITECTURES]='architectures'
83 local CONFIGS='systemd/bootchart.conf systemd/coredump.conf systemd/journald.conf
84 systemd/journal-remote.conf systemd/journal-upload.conf systemd/logind.conf
85 systemd/resolved.conf systemd/networkd.conf systemd/resolved.conf
86 systemd/sleep.conf systemd/system.conf systemd/timedated.conf
87 systemd/timesyncd.conf systemd/user.conf udev/udev.conf'
89 _init_completion || return
91 for ((i=0; i < COMP_CWORD; i++)); do
92 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
93 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
99 if __contains_word "--user" ${COMP_WORDS[*]}; then
105 if __contains_word "$prev" ${OPTS[ARG]}; then
108 comps=$(compgen -A hostname)
111 comps=$( __get_machines )
114 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
118 if [[ -z ${verb-} && $cur = -* ]]; then
119 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
123 if [[ -z ${verb-} ]]; then
126 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
127 if [[ $cur = -* ]]; then
128 comps='--help --version --system --user --global --no-pager'
131 elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then
132 if [[ $cur = -* ]]; then
133 comps='--help --version --system --user --fuzz --no-pager'
135 comps=$( __get_units_all $mode )
138 elif __contains_word "$verb" ${VERBS[DOT]}; then
139 if [[ $cur = -* ]]; then
140 comps='--help --version --system --user --global --from-pattern --to-pattern --order --require'
143 elif __contains_word "$verb" ${VERBS[DUMP]}; then
144 if [[ $cur = -* ]]; then
145 comps='--help --version --system --user --no-pager'
147 comps=$( __get_units_all $mode )
150 elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then
151 if [[ $cur = -* ]]; then
152 comps='--help --version --no-pager'
154 comps=$( __get_syscall_sets )
157 elif __contains_word "$verb" ${VERBS[VERIFY]}; then
158 if [[ $cur = -* ]]; then
159 comps='--help --version --system --user --global --man=no --generators=yes --root --image --recursive-errors=no --recursive-errors=yes --recursive-errors=one'
161 comps=$( compgen -A file -- "$cur";
162 __get_units_all $mode )
166 elif __contains_word "$verb" ${VERBS[CAT_CONFIG]}; then
167 if [[ $cur = -* ]]; then
168 comps='--help --version --root --no-pager'
169 elif [[ -z $cur ]]; then
173 comps="$CONFIGS $( compgen -A file -- "$cur" )"
177 elif __contains_word "$verb" ${VERBS[SECURITY]}; then
178 if [[ $cur = -* ]]; then
179 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'
180 elif ! __contains_word "--offline" ${COMP_WORDS[*]}; then
181 comps=$( __get_services $mode )
183 comps="$CONFIGS $( compgen -A file -- "$cur" )"
187 elif __contains_word "$verb" ${VERBS[CONDITION]}; then
188 if [[ $cur = -* ]]; then
189 comps='--help --version --system --user --global --no-pager --root --image'
190 elif [[ $prev = "-u" ]] || [[ $prev = "--unit" ]]; then
191 comps=$( __get_services $mode )
194 elif __contains_word "$verb" ${VERBS[INSPECT_ELF]}; then
195 if [[ $cur = -* ]]; then
196 comps='--help --version --json=off --json=pretty --json=short'
198 comps=$( compgen -A file -- "$cur" )
202 elif __contains_word "$verb" ${VERBS[PLOT]}; then
203 if [[ $cur = -* ]]; then
204 comps='--help --version --system --user --global --no-pager --json=off --json=pretty --json=short --table --no-legend'
207 elif __contains_word "$verb" ${VERBS[ARCHITECTURES]}; then
208 if [[ $cur = -* ]]; then
209 comps='--help --version --no-pager --json=off --json=pretty --json=short --no-legend'
211 comps=$( __get_architectures )
215 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
219 complete -F _systemd_analyze systemd-analyze