]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/systemd-analyze
Merge pull request #8624 from yuwata/fix-8371
[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 # 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 () {
23 local w word=$1; shift
24 for w in "$@"; do
25 [[ $w = "$word" ]] && return
26 done
27 }
28
29 __get_machines() {
30 local a b
31 machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
32 }
33
34 _systemd_analyze() {
35 local i verb comps
36 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
37
38 local -A OPTS=(
39 [STANDALONE]='-h --help --version --system --user --global --order --require --no-pager
40 --man=no --generators=yes'
41 [ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern'
42 )
43
44 local -A VERBS=(
45 [STANDALONE]='time blame plot dump unit-paths calendar'
46 [CRITICAL_CHAIN]='critical-chain'
47 [DOT]='dot'
48 [LOG_LEVEL]='log-level'
49 [LOG_TARGET]='log-target'
50 [VERIFY]='verify'
51 [SECCOMP_FILTER]='syscall-filter'
52 [SERVICE_WATCHDOGS]='service-watchdogs'
53 )
54
55 _init_completion || return
56
57 for ((i=0; i < COMP_CWORD; i++)); do
58 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
59 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
60 verb=${COMP_WORDS[i]}
61 break
62 fi
63 done
64
65 if __contains_word "$prev" ${OPTS[ARG]}; then
66 case $prev in
67 --host|-H)
68 comps=$(compgen -A hostname)
69 ;;
70 --machine|-M)
71 comps=$( __get_machines )
72 ;;
73 esac
74 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
75 return 0
76 fi
77
78 if [[ -z $verb && $cur = -* ]]; then
79 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
80 return 0
81 fi
82
83 if [[ -z $verb ]]; then
84 comps=${VERBS[*]}
85
86 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
87 if [[ $cur = -* ]]; then
88 comps='--help --version --system --user --global'
89 fi
90
91 elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then
92 if [[ $cur = -* ]]; then
93 comps='--help --version --system --user --fuzz'
94 fi
95
96 elif __contains_word "$verb" ${VERBS[DOT]}; then
97 if [[ $cur = -* ]]; then
98 comps='--help --version --system --user --global --from-pattern --to-pattern --order --require'
99 fi
100
101 elif __contains_word "$verb" ${VERBS[LOG_LEVEL]}; then
102 if [[ $cur = -* ]]; then
103 comps='--help --version --system --user'
104 else
105 comps='debug info notice warning err crit alert emerg'
106 fi
107
108 elif __contains_word "$verb" ${VERBS[LOG_TARGET]}; then
109 if [[ $cur = -* ]]; then
110 comps='--help --version --system --user'
111 else
112 comps='console journal kmsg journal-or-kmsg null'
113 fi
114
115 elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then
116 if [[ $cur = -* ]]; then
117 comps='--help --version'
118 fi
119
120 elif __contains_word "$verb" ${VERBS[VERIFY]}; then
121 if [[ $cur = -* ]]; then
122 comps='--help --version --system --user --global --man=no --generators=yes'
123 else
124 comps=$( compgen -A file -- "$cur" )
125 compopt -o filenames
126 fi
127
128 elif __contains_word "$verb" ${VERBS[SERVICE_WATCHDOGS]}; then
129 if [[ $cur = -* ]]; then
130 comps='--help --version --system --user'
131 else
132 comps='on off'
133 fi
134
135 fi
136
137 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
138 return 0
139 }
140
141 complete -F _systemd_analyze systemd-analyze