]>
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 | # | |
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=( | |
7c3940f6 YW |
39 | [STANDALONE]='-h --help --version --system --user --order --require --no-pager |
40 | --man=no --generators=yes' | |
41 | [ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern' | |
64ae7f18 | 42 | ) |
83cb95b5 HH |
43 | |
44 | local -A VERBS=( | |
7c3940f6 | 45 | [STANDALONE]='time blame plot dump get-log-level get-log-target calendar' |
bb150966 | 46 | [CRITICAL_CHAIN]='critical-chain' |
83cb95b5 | 47 | [DOT]='dot' |
fe05567c | 48 | [LOG_LEVEL]='set-log-level' |
4146ac2a | 49 | [LOG_TARGET]='set-log-target' |
2c12a402 | 50 | [VERIFY]='verify' |
869feb33 | 51 | [SECCOMP_FILTER]='syscall-filter' |
83cb95b5 HH |
52 | ) |
53 | ||
54 | _init_completion || return | |
55 | ||
3ce09b7d | 56 | for ((i=0; i < COMP_CWORD; i++)); do |
83cb95b5 HH |
57 | if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} && |
58 | ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then | |
59 | verb=${COMP_WORDS[i]} | |
60 | break | |
61 | fi | |
62 | done | |
63 | ||
64ae7f18 TA |
64 | if __contains_word "$prev" ${OPTS[ARG]}; then |
65 | case $prev in | |
66 | --host|-H) | |
67 | comps=$(compgen -A hostname) | |
68 | ;; | |
69 | --machine|-M) | |
70 | comps=$( __get_machines ) | |
71 | ;; | |
72 | esac | |
73 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
74 | return 0 | |
75 | fi | |
76 | ||
83cb95b5 HH |
77 | if [[ -z $verb && $cur = -* ]]; then |
78 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
79 | return 0 | |
80 | fi | |
81 | ||
82 | if [[ -z $verb ]]; then | |
83 | comps=${VERBS[*]} | |
84 | ||
299c397c | 85 | elif __contains_word "$verb" ${VERBS[STANDALONE]}; then |
83cb95b5 HH |
86 | if [[ $cur = -* ]]; then |
87 | comps='--help --version --system --user' | |
88 | fi | |
89 | ||
bb150966 HH |
90 | elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then |
91 | if [[ $cur = -* ]]; then | |
92 | comps='--help --version --system --user --fuzz' | |
93 | fi | |
94 | ||
83cb95b5 HH |
95 | elif __contains_word "$verb" ${VERBS[DOT]}; then |
96 | if [[ $cur = -* ]]; then | |
97 | comps='--help --version --system --user --from-pattern --to-pattern --order --require' | |
98 | fi | |
fe05567c ZJS |
99 | |
100 | elif __contains_word "$verb" ${VERBS[LOG_LEVEL]}; then | |
101 | if [[ $cur = -* ]]; then | |
102 | comps='--help --version --system --user' | |
103 | else | |
104 | comps='debug info notice warning err crit alert emerg' | |
105 | fi | |
106 | ||
4146ac2a LW |
107 | elif __contains_word "$verb" ${VERBS[LOG_TARGET]}; then |
108 | if [[ $cur = -* ]]; then | |
109 | comps='--help --version --system --user' | |
110 | else | |
111 | comps='console journal kmsg journal-or-kmsg null' | |
112 | fi | |
113 | ||
869feb33 ZJS |
114 | elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then |
115 | if [[ $cur = -* ]]; then | |
116 | comps='--help --version' | |
117 | fi | |
118 | ||
2c12a402 ZJS |
119 | elif __contains_word "$verb" ${VERBS[VERIFY]}; then |
120 | if [[ $cur = -* ]]; then | |
7c3940f6 | 121 | comps='--help --version --system --user --man=no --generators=yes' |
2c12a402 ZJS |
122 | else |
123 | comps=$( compgen -A file -- "$cur" ) | |
124 | compopt -o filenames | |
125 | fi | |
126 | ||
83cb95b5 HH |
127 | fi |
128 | ||
129 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
130 | return 0 | |
131 | } | |
132 | ||
133 | complete -F _systemd_analyze systemd-analyze |