]>
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=( | |
7c6de13f | 58 | [STANDALONE]='time blame plot dump unit-paths exit-status condition calendar timestamp timespan' |
843cfcb1 ZJS |
59 | [CRITICAL_CHAIN]='critical-chain' |
60 | [DOT]='dot' | |
843cfcb1 ZJS |
61 | [VERIFY]='verify' |
62 | [SECCOMP_FILTER]='syscall-filter' | |
843cfcb1 ZJS |
63 | [CAT_CONFIG]='cat-config' |
64 | [SECURITY]='security' | |
65 | ) | |
66 | ||
67 | local CONFIGS='systemd/bootchart.conf systemd/coredump.conf systemd/journald.conf | |
581ab537 YW |
68 | systemd/journal-remote.conf systemd/journal-upload.conf systemd/logind.conf |
69 | systemd/resolved.conf systemd/networkd.conf systemd/resolved.conf | |
70 | systemd/sleep.conf systemd/system.conf systemd/timedated.conf | |
71 | systemd/timesyncd.conf systemd/user.conf udev/udev.conf' | |
72 | ||
843cfcb1 ZJS |
73 | _init_completion || return |
74 | ||
75 | for ((i=0; i < COMP_CWORD; i++)); do | |
76 | if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} && | |
77 | ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then | |
78 | verb=${COMP_WORDS[i]} | |
79 | break | |
64ae7f18 | 80 | fi |
843cfcb1 ZJS |
81 | done |
82 | ||
83 | if __contains_word "$prev" ${OPTS[ARG]}; then | |
84 | case $prev in | |
85 | --host|-H) | |
86 | comps=$(compgen -A hostname) | |
87 | ;; | |
88 | --machine|-M) | |
89 | comps=$( __get_machines ) | |
90 | ;; | |
91 | esac | |
92 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
93 | return 0 | |
94 | fi | |
95 | ||
96 | if [[ -z $verb && $cur = -* ]]; then | |
97 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
98 | return 0 | |
99 | fi | |
100 | ||
101 | if [[ -z $verb ]]; then | |
102 | comps=${VERBS[*]} | |
64ae7f18 | 103 | |
843cfcb1 ZJS |
104 | elif __contains_word "$verb" ${VERBS[STANDALONE]}; then |
105 | if [[ $cur = -* ]]; then | |
106 | comps='--help --version --system --user --global --no-pager' | |
83cb95b5 HH |
107 | fi |
108 | ||
843cfcb1 ZJS |
109 | elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then |
110 | if [[ $cur = -* ]]; then | |
111 | comps='--help --version --system --user --fuzz --no-pager' | |
83cb95b5 HH |
112 | fi |
113 | ||
843cfcb1 ZJS |
114 | elif __contains_word "$verb" ${VERBS[DOT]}; then |
115 | if [[ $cur = -* ]]; then | |
116 | comps='--help --version --system --user --global --from-pattern --to-pattern --order --require' | |
117 | fi | |
118 | ||
843cfcb1 ZJS |
119 | elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then |
120 | if [[ $cur = -* ]]; then | |
121 | comps='--help --version --no-pager' | |
122 | else | |
123 | comps=$( __get_syscall_sets ) | |
124 | fi | |
125 | ||
126 | elif __contains_word "$verb" ${VERBS[VERIFY]}; then | |
127 | if [[ $cur = -* ]]; then | |
128 | comps='--help --version --system --user --global --man=no --generators=yes' | |
129 | else | |
130 | comps=$( compgen -A file -- "$cur" ) | |
131 | compopt -o filenames | |
132 | fi | |
133 | ||
843cfcb1 ZJS |
134 | elif __contains_word "$verb" ${VERBS[CAT_CONFIG]}; then |
135 | if [[ $cur = -* ]]; then | |
136 | comps='--help --version --root --no-pager' | |
137 | elif [[ -z $cur ]]; then | |
138 | comps="$CONFIGS" | |
139 | compopt -o filenames | |
140 | else | |
141 | comps="$CONFIGS $( compgen -A file -- "$cur" )" | |
142 | compopt -o filenames | |
143 | fi | |
144 | ||
145 | elif __contains_word "$verb" ${VERBS[SECURITY]}; then | |
146 | if [[ $cur = -* ]]; then | |
147 | comps='--help --version --no-pager --system --user -H --host -M --machine' | |
148 | else | |
149 | if __contains_word "--user" ${COMP_WORDS[*]}; then | |
150 | mode=--user | |
151 | else | |
152 | mode=--system | |
153 | fi | |
154 | comps=$( __get_services $mode ) | |
155 | fi | |
156 | fi | |
157 | ||
158 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
159 | return 0 | |
83cb95b5 HH |
160 | } |
161 | ||
162 | complete -F _systemd_analyze systemd-analyze |