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 }
39 local i verb comps mode
40 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
43 [STANDALONE]='-h --help --version --system --user --global --order --require --no-pager
44 --man=no --generators=yes'
45 [ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern --root'
49 [STANDALONE]='time blame plot dump unit-paths calendar timespan'
50 [CRITICAL_CHAIN]='critical-chain'
52 [LOG_LEVEL]='log-level'
53 [LOG_TARGET]='log-target'
55 [SECCOMP_FILTER]='syscall-filter'
56 [SERVICE_WATCHDOGS]='service-watchdogs'
57 [CAT_CONFIG]='cat-config'
61 local CONFIGS='systemd/bootchart.conf systemd/coredump.conf systemd/journald.conf
62 systemd/journal-remote.conf systemd/journal-upload.conf systemd/logind.conf
63 systemd/resolved.conf systemd/networkd.conf systemd/resolved.conf
64 systemd/sleep.conf systemd/system.conf systemd/timedated.conf
65 systemd/timesyncd.conf systemd/user.conf udev/udev.conf'
67 _init_completion || return
69 for ((i=0; i < COMP_CWORD; i++)); do
70 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
71 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
77 if __contains_word "$prev" ${OPTS[ARG]}; then
80 comps=$(compgen -A hostname)
83 comps=$( __get_machines )
86 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
90 if [[ -z $verb && $cur = -* ]]; then
91 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
95 if [[ -z $verb ]]; then
98 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
99 if [[ $cur = -* ]]; then
100 comps='--help --version --system --user --global --no-pager'
103 elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then
104 if [[ $cur = -* ]]; then
105 comps='--help --version --system --user --fuzz --no-pager'
108 elif __contains_word "$verb" ${VERBS[DOT]}; then
109 if [[ $cur = -* ]]; then
110 comps='--help --version --system --user --global --from-pattern --to-pattern --order --require'
113 elif __contains_word "$verb" ${VERBS[LOG_LEVEL]}; then
114 if [[ $cur = -* ]]; then
115 comps='--help --version --system --user'
117 comps='debug info notice warning err crit alert emerg'
120 elif __contains_word "$verb" ${VERBS[LOG_TARGET]}; then
121 if [[ $cur = -* ]]; then
122 comps='--help --version --system --user'
124 comps='console journal kmsg journal-or-kmsg null'
127 elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then
128 if [[ $cur = -* ]]; then
129 comps='--help --version --no-pager'
132 elif __contains_word "$verb" ${VERBS[VERIFY]}; then
133 if [[ $cur = -* ]]; then
134 comps='--help --version --system --user --global --man=no --generators=yes'
136 comps=$( compgen -A file -- "$cur" )
140 elif __contains_word "$verb" ${VERBS[SERVICE_WATCHDOGS]}; then
141 if [[ $cur = -* ]]; then
142 comps='--help --version --system --user'
147 elif __contains_word "$verb" ${VERBS[CAT_CONFIG]}; then
148 if [[ $cur = -* ]]; then
149 comps='--help --version --root --no-pager'
150 elif [[ -z $cur ]]; then
154 comps="$CONFIGS $( compgen -A file -- "$cur" )"
158 elif __contains_word "$verb" ${VERBS[SECURITY]}; then
159 if [[ $cur = -* ]]; then
160 comps='--help --version --no-pager --system --user -H --host -M --machine'
162 if __contains_word "--user" ${COMP_WORDS[*]}; then
167 comps=$( __get_services $mode )
171 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
175 complete -F _systemd_analyze systemd-analyze