]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/systemd-analyze
pkgconfig: define variables relative to ${prefix}/${rootprefix}/${sysconfdir}
[thirdparty/systemd.git] / shell-completion / bash / systemd-analyze
1 # systemd-analyze(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
3 #
4 # This file is part of systemd.
5 #
6 # Copyright © 2010 Ran Benita
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 () {
22 local w word=$1; shift
23 for w in "$@"; do
24 [[ $w = "$word" ]] && return
25 done
26 }
27
28 __get_machines() {
29 local a b
30 machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
31 }
32
33 _systemd_analyze() {
34 local i verb comps
35 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
36
37 local -A OPTS=(
38 [STANDALONE]='-h --help --version --system --user --global --order --require --no-pager
39 --man=no --generators=yes'
40 [ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern --root'
41 )
42
43 local -A VERBS=(
44 [STANDALONE]='time blame plot dump unit-paths calendar timespan'
45 [CRITICAL_CHAIN]='critical-chain'
46 [DOT]='dot'
47 [LOG_LEVEL]='log-level'
48 [LOG_TARGET]='log-target'
49 [VERIFY]='verify'
50 [SECCOMP_FILTER]='syscall-filter'
51 [SERVICE_WATCHDOGS]='service-watchdogs'
52 [CAT_CONFIG]='cat-config'
53 )
54
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
61 _init_completion || return
62
63 for ((i=0; i < COMP_CWORD; i++)); do
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
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
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
92 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
93 if [[ $cur = -* ]]; then
94 comps='--help --version --system --user --global --no-pager'
95 fi
96
97 elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then
98 if [[ $cur = -* ]]; then
99 comps='--help --version --system --user --fuzz --no-pager'
100 fi
101
102 elif __contains_word "$verb" ${VERBS[DOT]}; then
103 if [[ $cur = -* ]]; then
104 comps='--help --version --system --user --global --from-pattern --to-pattern --order --require'
105 fi
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
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
121 elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then
122 if [[ $cur = -* ]]; then
123 comps='--help --version --no-pager'
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
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
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
151 fi
152
153 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
154 return 0
155 }
156
157 complete -F _systemd_analyze systemd-analyze