]> git.ipfire.org Git - thirdparty/systemd.git/blame - shell-completion/bash/systemd-analyze
bash-completion: analyze: support cat-config verb
[thirdparty/systemd.git] / shell-completion / bash / systemd-analyze
CommitLineData
83cb95b5 1# systemd-analyze(1) completion -*- shell-script -*-
7059062c 2# SPDX-License-Identifier: LGPL-2.1+
83cb95b5
HH
3#
4# This file is part of systemd.
5#
6# Copyright 2010 Ran Benita
7# Copyright 2013 Harald Hoyer
8#
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.
13#
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.
18#
19# You should have received a copy of the GNU Lesser General Public License
20# along with systemd; If not, see <http://www.gnu.org/licenses/>.
21
22__contains_word () {
a72d698d
DR
23 local w word=$1; shift
24 for w in "$@"; do
25 [[ $w = "$word" ]] && return
26 done
83cb95b5
HH
27}
28
64ae7f18
TA
29__get_machines() {
30 local a b
31 machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
32}
33
83cb95b5
HH
34_systemd_analyze() {
35 local i verb comps
36 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
64ae7f18
TA
37
38 local -A OPTS=(
ecd3717a 39 [STANDALONE]='-h --help --version --system --user --global --order --require --no-pager
7c3940f6 40 --man=no --generators=yes'
581ab537 41 [ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern --root'
64ae7f18 42 )
83cb95b5
HH
43
44 local -A VERBS=(
ecd3717a 45 [STANDALONE]='time blame plot dump unit-paths calendar'
bb150966 46 [CRITICAL_CHAIN]='critical-chain'
83cb95b5 47 [DOT]='dot'
90657286
YW
48 [LOG_LEVEL]='log-level'
49 [LOG_TARGET]='log-target'
2c12a402 50 [VERIFY]='verify'
869feb33 51 [SECCOMP_FILTER]='syscall-filter'
21a6abdf 52 [SERVICE_WATCHDOGS]='service-watchdogs'
581ab537 53 [CAT_CONFIG]='cat-config'
83cb95b5
HH
54 )
55
581ab537
YW
56 local CONFIGS='systemd/bootchart.conf systemd/coredump.conf systemd/journald.conf
57 systemd/journal-remote.conf systemd/journal-upload.conf systemd/logind.conf
58 systemd/resolved.conf systemd/networkd.conf systemd/resolved.conf
59 systemd/sleep.conf systemd/system.conf systemd/timedated.conf
60 systemd/timesyncd.conf systemd/user.conf udev/udev.conf'
61
83cb95b5
HH
62 _init_completion || return
63
3ce09b7d 64 for ((i=0; i < COMP_CWORD; i++)); do
83cb95b5
HH
65 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
66 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
67 verb=${COMP_WORDS[i]}
68 break
69 fi
70 done
71
64ae7f18
TA
72 if __contains_word "$prev" ${OPTS[ARG]}; then
73 case $prev in
74 --host|-H)
75 comps=$(compgen -A hostname)
76 ;;
77 --machine|-M)
78 comps=$( __get_machines )
79 ;;
80 esac
81 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
82 return 0
83 fi
84
83cb95b5
HH
85 if [[ -z $verb && $cur = -* ]]; then
86 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
87 return 0
88 fi
89
90 if [[ -z $verb ]]; then
91 comps=${VERBS[*]}
92
299c397c 93 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
83cb95b5 94 if [[ $cur = -* ]]; then
7ee19d26 95 comps='--help --version --system --user --global --no-pager'
83cb95b5
HH
96 fi
97
bb150966
HH
98 elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then
99 if [[ $cur = -* ]]; then
7ee19d26 100 comps='--help --version --system --user --fuzz --no-pager'
bb150966
HH
101 fi
102
83cb95b5
HH
103 elif __contains_word "$verb" ${VERBS[DOT]}; then
104 if [[ $cur = -* ]]; then
ecd3717a 105 comps='--help --version --system --user --global --from-pattern --to-pattern --order --require'
83cb95b5 106 fi
fe05567c
ZJS
107
108 elif __contains_word "$verb" ${VERBS[LOG_LEVEL]}; then
109 if [[ $cur = -* ]]; then
110 comps='--help --version --system --user'
111 else
112 comps='debug info notice warning err crit alert emerg'
113 fi
114
4146ac2a
LW
115 elif __contains_word "$verb" ${VERBS[LOG_TARGET]}; then
116 if [[ $cur = -* ]]; then
117 comps='--help --version --system --user'
118 else
119 comps='console journal kmsg journal-or-kmsg null'
120 fi
121
869feb33
ZJS
122 elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then
123 if [[ $cur = -* ]]; then
7ee19d26 124 comps='--help --version --no-pager'
869feb33
ZJS
125 fi
126
2c12a402
ZJS
127 elif __contains_word "$verb" ${VERBS[VERIFY]}; then
128 if [[ $cur = -* ]]; then
ecd3717a 129 comps='--help --version --system --user --global --man=no --generators=yes'
2c12a402
ZJS
130 else
131 comps=$( compgen -A file -- "$cur" )
132 compopt -o filenames
133 fi
134
21a6abdf
JK
135 elif __contains_word "$verb" ${VERBS[SERVICE_WATCHDOGS]}; then
136 if [[ $cur = -* ]]; then
137 comps='--help --version --system --user'
138 else
139 comps='on off'
140 fi
141
581ab537
YW
142 elif __contains_word "$verb" ${VERBS[CAT_CONFIG]}; then
143 if [[ $cur = -* ]]; then
144 comps='--help --version --root --no-pager'
145 elif [[ -z $cur ]]; then
146 comps="$CONFIGS"
147 compopt -o filenames
148 else
149 comps="$CONFIGS $( compgen -A file -- "$cur" )"
150 compopt -o filenames
151 fi
83cb95b5
HH
152 fi
153
154 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
155 return 0
156}
157
158complete -F _systemd_analyze systemd-analyze