1 # systemd-analyze(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
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 <http://www.gnu.org/licenses/>.
22 local w word=$1; shift
24 [[ $w = "$word" ]] && return
30 machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
34 systemctl list-units --no-legend --no-pager -t service --all $1 | \
35 { while read -r a b c; do [[ $b == "loaded" ]]; echo " $a"; done }
38 __get_syscall_sets() {
40 systemd-analyze syscall-filter --no-pager | while IFS= read -r line; do
41 if [[ $line == @* ]]; then
48 local i verb comps mode
49 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
52 [STANDALONE]='-h --help --version --system --user --global --order --require --no-pager
53 --man=no --generators=yes'
54 [ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern --root'
58 [STANDALONE]='time blame plot dump unit-paths calendar timespan'
59 [CRITICAL_CHAIN]='critical-chain'
61 [LOG_LEVEL]='log-level'
62 [LOG_TARGET]='log-target'
64 [SECCOMP_FILTER]='syscall-filter'
65 [SERVICE_WATCHDOGS]='service-watchdogs'
66 [CAT_CONFIG]='cat-config'
70 local CONFIGS='systemd/bootchart.conf systemd/coredump.conf systemd/journald.conf
71 systemd/journal-remote.conf systemd/journal-upload.conf systemd/logind.conf
72 systemd/resolved.conf systemd/networkd.conf systemd/resolved.conf
73 systemd/sleep.conf systemd/system.conf systemd/timedated.conf
74 systemd/timesyncd.conf systemd/user.conf udev/udev.conf'
76 _init_completion || return
78 for ((i=0; i < COMP_CWORD; i++)); do
79 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
80 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
86 if __contains_word "$prev" ${OPTS[ARG]}; then
89 comps=$(compgen -A hostname)
92 comps=$( __get_machines )
95 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
99 if [[ -z $verb && $cur = -* ]]; then
100 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
104 if [[ -z $verb ]]; then
107 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
108 if [[ $cur = -* ]]; then
109 comps='--help --version --system --user --global --no-pager'
112 elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then
113 if [[ $cur = -* ]]; then
114 comps='--help --version --system --user --fuzz --no-pager'
117 elif __contains_word "$verb" ${VERBS[DOT]}; then
118 if [[ $cur = -* ]]; then
119 comps='--help --version --system --user --global --from-pattern --to-pattern --order --require'
122 elif __contains_word "$verb" ${VERBS[LOG_LEVEL]}; then
123 if [[ $cur = -* ]]; then
124 comps='--help --version --system --user'
126 comps='debug info notice warning err crit alert emerg'
129 elif __contains_word "$verb" ${VERBS[LOG_TARGET]}; then
130 if [[ $cur = -* ]]; then
131 comps='--help --version --system --user'
133 comps='console journal kmsg journal-or-kmsg null'
136 elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then
137 if [[ $cur = -* ]]; then
138 comps='--help --version --no-pager'
140 comps=$( __get_syscall_sets )
143 elif __contains_word "$verb" ${VERBS[VERIFY]}; then
144 if [[ $cur = -* ]]; then
145 comps='--help --version --system --user --global --man=no --generators=yes'
147 comps=$( compgen -A file -- "$cur" )
151 elif __contains_word "$verb" ${VERBS[SERVICE_WATCHDOGS]}; then
152 if [[ $cur = -* ]]; then
153 comps='--help --version --system --user'
158 elif __contains_word "$verb" ${VERBS[CAT_CONFIG]}; then
159 if [[ $cur = -* ]]; then
160 comps='--help --version --root --no-pager'
161 elif [[ -z $cur ]]; then
165 comps="$CONFIGS $( compgen -A file -- "$cur" )"
169 elif __contains_word "$verb" ${VERBS[SECURITY]}; then
170 if [[ $cur = -* ]]; then
171 comps='--help --version --no-pager --system --user -H --host -M --machine'
173 if __contains_word "--user" ${COMP_WORDS[*]}; then
178 comps=$( __get_services $mode )
182 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
186 complete -F _systemd_analyze systemd-analyze