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