]>
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 () { | |
843cfcb1 ZJS |
22 | local w word=$1; shift |
23 | for w in "$@"; do | |
24 | [[ $w = "$word" ]] && return | |
25 | done | |
83cb95b5 HH |
26 | } |
27 | ||
64ae7f18 | 28 | __get_machines() { |
843cfcb1 ZJS |
29 | local a b |
30 | machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; }; | |
64ae7f18 TA |
31 | } |
32 | ||
83da42c3 | 33 | __get_services() { |
843cfcb1 ZJS |
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 } | |
83da42c3 YW |
36 | } |
37 | ||
2431ca22 | 38 | __get_syscall_sets() { |
843cfcb1 ZJS |
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 | |
2431ca22 LW |
45 | } |
46 | ||
83cb95b5 | 47 | _systemd_analyze() { |
843cfcb1 ZJS |
48 | local i verb comps mode |
49 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} | |
64ae7f18 | 50 | |
843cfcb1 ZJS |
51 | local -A OPTS=( |
52 | [STANDALONE]='-h --help --version --system --user --global --order --require --no-pager | |
7c3940f6 | 53 | --man=no --generators=yes' |
843cfcb1 ZJS |
54 | [ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern --root' |
55 | ) | |
56 | ||
57 | local -A VERBS=( | |
58 | [STANDALONE]='time blame plot dump unit-paths calendar timespan' | |
59 | [CRITICAL_CHAIN]='critical-chain' | |
60 | [DOT]='dot' | |
61 | [LOG_LEVEL]='log-level' | |
62 | [LOG_TARGET]='log-target' | |
63 | [VERIFY]='verify' | |
64 | [SECCOMP_FILTER]='syscall-filter' | |
65 | [SERVICE_WATCHDOGS]='service-watchdogs' | |
66 | [CAT_CONFIG]='cat-config' | |
67 | [SECURITY]='security' | |
68 | ) | |
69 | ||
70 | local CONFIGS='systemd/bootchart.conf systemd/coredump.conf systemd/journald.conf | |
581ab537 YW |
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 | ||
843cfcb1 ZJS |
76 | _init_completion || return |
77 | ||
78 | for ((i=0; i < COMP_CWORD; i++)); do | |
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 | |
64ae7f18 | 83 | fi |
843cfcb1 ZJS |
84 | done |
85 | ||
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 | ||
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[*]} | |
64ae7f18 | 106 | |
843cfcb1 ZJS |
107 | elif __contains_word "$verb" ${VERBS[STANDALONE]}; then |
108 | if [[ $cur = -* ]]; then | |
109 | comps='--help --version --system --user --global --no-pager' | |
83cb95b5 HH |
110 | fi |
111 | ||
843cfcb1 ZJS |
112 | elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then |
113 | if [[ $cur = -* ]]; then | |
114 | comps='--help --version --system --user --fuzz --no-pager' | |
83cb95b5 HH |
115 | fi |
116 | ||
843cfcb1 ZJS |
117 | elif __contains_word "$verb" ${VERBS[DOT]}; then |
118 | if [[ $cur = -* ]]; then | |
119 | comps='--help --version --system --user --global --from-pattern --to-pattern --order --require' | |
120 | fi | |
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 | ||
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 | ||
136 | elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then | |
137 | if [[ $cur = -* ]]; then | |
138 | comps='--help --version --no-pager' | |
139 | else | |
140 | comps=$( __get_syscall_sets ) | |
141 | fi | |
142 | ||
143 | elif __contains_word "$verb" ${VERBS[VERIFY]}; then | |
144 | if [[ $cur = -* ]]; then | |
145 | comps='--help --version --system --user --global --man=no --generators=yes' | |
146 | else | |
147 | comps=$( compgen -A file -- "$cur" ) | |
148 | compopt -o filenames | |
149 | fi | |
150 | ||
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 | ||
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 | |
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 | |
180 | fi | |
181 | ||
182 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
183 | return 0 | |
83cb95b5 HH |
184 | } |
185 | ||
186 | complete -F _systemd_analyze systemd-analyze |