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