]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/systemd-analyze
bash-completion: busctl: support --json and -j option
[thirdparty/systemd.git] / shell-completion / bash / systemd-analyze
1 # systemd-analyze(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
3 #
4 # This file is part of systemd.
5 #
6 # Copyright © 2010 Ran Benita
7 #
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.
12 #
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.
17 #
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/>.
20
21 __contains_word () {
22 local w word=$1; shift
23 for w in "$@"; do
24 [[ $w = "$word" ]] && return
25 done
26 }
27
28 __get_machines() {
29 local a b
30 machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
31 }
32
33 __get_services() {
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 }
36 }
37
38 _systemd_analyze() {
39 local i verb comps mode
40 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
41
42 local -A OPTS=(
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'
46 )
47
48 local -A VERBS=(
49 [STANDALONE]='time blame plot dump unit-paths calendar timespan'
50 [CRITICAL_CHAIN]='critical-chain'
51 [DOT]='dot'
52 [LOG_LEVEL]='log-level'
53 [LOG_TARGET]='log-target'
54 [VERIFY]='verify'
55 [SECCOMP_FILTER]='syscall-filter'
56 [SERVICE_WATCHDOGS]='service-watchdogs'
57 [CAT_CONFIG]='cat-config'
58 [SECURITY]='security'
59 )
60
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'
66
67 _init_completion || return
68
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
72 verb=${COMP_WORDS[i]}
73 break
74 fi
75 done
76
77 if __contains_word "$prev" ${OPTS[ARG]}; then
78 case $prev in
79 --host|-H)
80 comps=$(compgen -A hostname)
81 ;;
82 --machine|-M)
83 comps=$( __get_machines )
84 ;;
85 esac
86 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
87 return 0
88 fi
89
90 if [[ -z $verb && $cur = -* ]]; then
91 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
92 return 0
93 fi
94
95 if [[ -z $verb ]]; then
96 comps=${VERBS[*]}
97
98 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
99 if [[ $cur = -* ]]; then
100 comps='--help --version --system --user --global --no-pager'
101 fi
102
103 elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then
104 if [[ $cur = -* ]]; then
105 comps='--help --version --system --user --fuzz --no-pager'
106 fi
107
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'
111 fi
112
113 elif __contains_word "$verb" ${VERBS[LOG_LEVEL]}; then
114 if [[ $cur = -* ]]; then
115 comps='--help --version --system --user'
116 else
117 comps='debug info notice warning err crit alert emerg'
118 fi
119
120 elif __contains_word "$verb" ${VERBS[LOG_TARGET]}; then
121 if [[ $cur = -* ]]; then
122 comps='--help --version --system --user'
123 else
124 comps='console journal kmsg journal-or-kmsg null'
125 fi
126
127 elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then
128 if [[ $cur = -* ]]; then
129 comps='--help --version --no-pager'
130 fi
131
132 elif __contains_word "$verb" ${VERBS[VERIFY]}; then
133 if [[ $cur = -* ]]; then
134 comps='--help --version --system --user --global --man=no --generators=yes'
135 else
136 comps=$( compgen -A file -- "$cur" )
137 compopt -o filenames
138 fi
139
140 elif __contains_word "$verb" ${VERBS[SERVICE_WATCHDOGS]}; then
141 if [[ $cur = -* ]]; then
142 comps='--help --version --system --user'
143 else
144 comps='on off'
145 fi
146
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
151 comps="$CONFIGS"
152 compopt -o filenames
153 else
154 comps="$CONFIGS $( compgen -A file -- "$cur" )"
155 compopt -o filenames
156 fi
157
158 elif __contains_word "$verb" ${VERBS[SECURITY]}; then
159 if [[ $cur = -* ]]; then
160 comps='--help --version --no-pager --system --user -H --host -M --machine'
161 else
162 if __contains_word "--user" ${COMP_WORDS[*]}; then
163 mode=--user
164 else
165 mode=--system
166 fi
167 comps=$( __get_services $mode )
168 fi
169 fi
170
171 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
172 return 0
173 }
174
175 complete -F _systemd_analyze systemd-analyze