]>
Commit | Line | Data |
---|---|---|
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 | ||
83da42c3 YW |
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 | ||
2431ca22 LW |
38 | __get_syscall_sets() { |
39 | local line | |
40 | systemd-analyze syscall-filter --no-pager | while IFS= read -r line; do | |
41 | if [[ $line == @* ]]; then | |
42 | printf '%s\n' "$line" | |
43 | fi | |
44 | done | |
45 | } | |
46 | ||
83cb95b5 | 47 | _systemd_analyze() { |
83da42c3 | 48 | local i verb comps mode |
83cb95b5 | 49 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} |
64ae7f18 TA |
50 | |
51 | local -A OPTS=( | |
ecd3717a | 52 | [STANDALONE]='-h --help --version --system --user --global --order --require --no-pager |
7c3940f6 | 53 | --man=no --generators=yes' |
581ab537 | 54 | [ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern --root' |
64ae7f18 | 55 | ) |
83cb95b5 HH |
56 | |
57 | local -A VERBS=( | |
cb39201e | 58 | [STANDALONE]='time blame plot dump unit-paths calendar timespan' |
bb150966 | 59 | [CRITICAL_CHAIN]='critical-chain' |
83cb95b5 | 60 | [DOT]='dot' |
90657286 YW |
61 | [LOG_LEVEL]='log-level' |
62 | [LOG_TARGET]='log-target' | |
2c12a402 | 63 | [VERIFY]='verify' |
869feb33 | 64 | [SECCOMP_FILTER]='syscall-filter' |
21a6abdf | 65 | [SERVICE_WATCHDOGS]='service-watchdogs' |
581ab537 | 66 | [CAT_CONFIG]='cat-config' |
83da42c3 | 67 | [SECURITY]='security' |
83cb95b5 HH |
68 | ) |
69 | ||
581ab537 YW |
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' | |
75 | ||
83cb95b5 HH |
76 | _init_completion || return |
77 | ||
3ce09b7d | 78 | for ((i=0; i < COMP_CWORD; i++)); do |
83cb95b5 HH |
79 | if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} && |
80 | ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then | |
81 | verb=${COMP_WORDS[i]} | |
82 | break | |
83 | fi | |
84 | done | |
85 | ||
64ae7f18 TA |
86 | if __contains_word "$prev" ${OPTS[ARG]}; then |
87 | case $prev in | |
88 | --host|-H) | |
89 | comps=$(compgen -A hostname) | |
90 | ;; | |
91 | --machine|-M) | |
92 | comps=$( __get_machines ) | |
93 | ;; | |
94 | esac | |
95 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
96 | return 0 | |
97 | fi | |
98 | ||
83cb95b5 HH |
99 | if [[ -z $verb && $cur = -* ]]; then |
100 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
101 | return 0 | |
102 | fi | |
103 | ||
104 | if [[ -z $verb ]]; then | |
105 | comps=${VERBS[*]} | |
106 | ||
299c397c | 107 | elif __contains_word "$verb" ${VERBS[STANDALONE]}; then |
83cb95b5 | 108 | if [[ $cur = -* ]]; then |
7ee19d26 | 109 | comps='--help --version --system --user --global --no-pager' |
83cb95b5 HH |
110 | fi |
111 | ||
bb150966 HH |
112 | elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then |
113 | if [[ $cur = -* ]]; then | |
7ee19d26 | 114 | comps='--help --version --system --user --fuzz --no-pager' |
bb150966 HH |
115 | fi |
116 | ||
83cb95b5 HH |
117 | elif __contains_word "$verb" ${VERBS[DOT]}; then |
118 | if [[ $cur = -* ]]; then | |
ecd3717a | 119 | comps='--help --version --system --user --global --from-pattern --to-pattern --order --require' |
83cb95b5 | 120 | fi |
fe05567c ZJS |
121 | |
122 | elif __contains_word "$verb" ${VERBS[LOG_LEVEL]}; then | |
123 | if [[ $cur = -* ]]; then | |
124 | comps='--help --version --system --user' | |
125 | else | |
126 | comps='debug info notice warning err crit alert emerg' | |
127 | fi | |
128 | ||
4146ac2a LW |
129 | elif __contains_word "$verb" ${VERBS[LOG_TARGET]}; then |
130 | if [[ $cur = -* ]]; then | |
131 | comps='--help --version --system --user' | |
132 | else | |
133 | comps='console journal kmsg journal-or-kmsg null' | |
134 | fi | |
135 | ||
869feb33 ZJS |
136 | elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then |
137 | if [[ $cur = -* ]]; then | |
7ee19d26 | 138 | comps='--help --version --no-pager' |
2431ca22 LW |
139 | else |
140 | comps=$( __get_syscall_sets ) | |
869feb33 ZJS |
141 | fi |
142 | ||
2c12a402 ZJS |
143 | elif __contains_word "$verb" ${VERBS[VERIFY]}; then |
144 | if [[ $cur = -* ]]; then | |
ecd3717a | 145 | comps='--help --version --system --user --global --man=no --generators=yes' |
2c12a402 ZJS |
146 | else |
147 | comps=$( compgen -A file -- "$cur" ) | |
148 | compopt -o filenames | |
149 | fi | |
150 | ||
21a6abdf JK |
151 | elif __contains_word "$verb" ${VERBS[SERVICE_WATCHDOGS]}; then |
152 | if [[ $cur = -* ]]; then | |
153 | comps='--help --version --system --user' | |
154 | else | |
155 | comps='on off' | |
156 | fi | |
157 | ||
581ab537 YW |
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 | |
162 | comps="$CONFIGS" | |
163 | compopt -o filenames | |
164 | else | |
165 | comps="$CONFIGS $( compgen -A file -- "$cur" )" | |
166 | compopt -o filenames | |
167 | fi | |
83da42c3 YW |
168 | |
169 | elif __contains_word "$verb" ${VERBS[SECURITY]}; then | |
170 | if [[ $cur = -* ]]; then | |
171 | comps='--help --version --no-pager --system --user -H --host -M --machine' | |
172 | else | |
173 | if __contains_word "--user" ${COMP_WORDS[*]}; then | |
174 | mode=--user | |
175 | else | |
176 | mode=--system | |
177 | fi | |
178 | comps=$( __get_services $mode ) | |
179 | fi | |
83cb95b5 HH |
180 | fi |
181 | ||
182 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
183 | return 0 | |
184 | } | |
185 | ||
186 | complete -F _systemd_analyze systemd-analyze |