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 capability compare-versions calendar timestamp timespan pcrs srk'
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'
85 local CONFIGS='locale.conf systemd/bootchart.conf systemd/coredump.conf systemd/journald.conf
86 systemd/journal-remote.conf systemd/journal-upload.conf systemd/logind.conf
87 systemd/resolved.conf systemd/networkd.conf systemd/pstore.conf systemd/resolved.conf
88 systemd/sleep.conf systemd/system.conf systemd/timedated.conf
89 systemd/timesyncd.conf systemd/user.conf udev/udev.conf'
91 _init_completion || return
93 for ((i=0; i < COMP_CWORD; i++)); do
94 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
95 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
101 if __contains_word "--user" ${COMP_WORDS[*]}; then
107 if __contains_word "$prev" ${OPTS[ARG]}; then
110 comps=$(compgen -A hostname)
113 comps=$( __get_machines )
116 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
120 if [[ -z ${verb-} && $cur = -* ]]; then
121 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
125 if [[ -z ${verb-} ]]; then
128 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
129 if [[ $cur = -* ]]; then
130 comps='--help --version --system --user --global --no-pager'
133 elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then
134 if [[ $cur = -* ]]; then
135 comps='--help --version --system --user --fuzz --no-pager'
137 comps=$( __get_units_all $mode )
140 elif __contains_word "$verb" ${VERBS[DOT]}; then
141 if [[ $cur = -* ]]; then
142 comps='--help --version --system --user --global --from-pattern --to-pattern --order --require'
145 elif __contains_word "$verb" ${VERBS[DUMP]}; then
146 if [[ $cur = -* ]]; then
147 comps='--help --version --system --user --no-pager'
149 comps=$( __get_units_all $mode )
152 elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then
153 if [[ $cur = -* ]]; then
154 comps='--help --version --no-pager'
156 comps=$( __get_syscall_sets )
159 elif __contains_word "$verb" ${VERBS[VERIFY]}; then
160 if [[ $cur = -* ]]; then
161 comps='--help --version --system --user --global --man=no --generators=yes --root --image --recursive-errors=no --recursive-errors=yes --recursive-errors=one'
163 comps=$( compgen -A file -- "$cur";
164 __get_units_all $mode )
168 elif __contains_word "$verb" ${VERBS[CAT_CONFIG]}; then
169 if [[ $cur = -* ]]; then
170 comps='--help --version --root --no-pager'
171 elif [[ -z $cur ]]; then
175 comps="$CONFIGS $( compgen -A file -- "$cur" )"
179 elif __contains_word "$verb" ${VERBS[SECURITY]}; then
180 if [[ $cur = -* ]]; then
181 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'
182 elif ! __contains_word "--offline" ${COMP_WORDS[*]}; then
183 comps=$( __get_services $mode )
185 comps="$CONFIGS $( compgen -A file -- "$cur" )"
189 elif __contains_word "$verb" ${VERBS[CONDITION]}; then
190 if [[ $cur = -* ]]; then
191 comps='--help --version --system --user --global --no-pager --root --image'
192 elif [[ $prev = "-u" ]] || [[ $prev = "--unit" ]]; then
193 comps=$( __get_services $mode )
196 elif __contains_word "$verb" ${VERBS[INSPECT_ELF]}; then
197 if [[ $cur = -* ]]; then
198 comps='--help --version --json=off --json=pretty --json=short'
200 comps=$( compgen -A file -- "$cur" )
204 elif __contains_word "$verb" ${VERBS[PLOT]}; then
205 if [[ $cur = -* ]]; then
206 comps='--help --version --system --user --global --no-pager --json=off --json=pretty --json=short --table --no-legend'
209 elif __contains_word "$verb" ${VERBS[ARCHITECTURES]}; then
210 if [[ $cur = -* ]]; then
211 comps='--help --version --no-pager --json=off --json=pretty --json=short --no-legend'
213 comps=$( __get_architectures )
216 elif __contains_word "$verb" ${VERBS[FDSTORE]}; then
217 if [[ $cur = -* ]]; then
218 comps='--help --version --system --user --global -H --host -M --machine --no-pager --json=off --json=pretty --json=short --root --image'
220 comps=$( __get_services $mode )
224 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
228 complete -F _systemd_analyze systemd-analyze