| 1 |
# shellcheck shell=bash |
| 2 |
# systemd-analyze(1) completion -*- shell-script -*- |
| 3 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
# |
| 5 |
# This file is part of systemd. |
| 6 |
# |
| 7 |
# Copyright © 2010 Ran Benita |
| 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 <https://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 --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | |
| 32 |
{ while read -r a b; do echo " $a"; done; } | |
| 33 |
sort -u |
| 34 |
} |
| 35 |
|
| 36 |
__get_units_all() { |
| 37 |
systemctl list-units --no-legend --no-pager --plain --all $1 2>/dev/null | |
| 38 |
{ while read -r a b c; do echo " $a"; done; } |
| 39 |
} |
| 40 |
|
| 41 |
__get_services() { |
| 42 |
systemctl list-units --no-legend --no-pager --plain -t service --all $1 2>/dev/null | |
| 43 |
{ while read -r a b c; do [[ $b == "loaded" ]] && echo " $a"; done; } |
| 44 |
} |
| 45 |
|
| 46 |
__get_syscall_sets() { |
| 47 |
local line |
| 48 |
systemd-analyze syscall-filter --no-pager 2>/dev/null | while IFS= read -r line; do |
| 49 |
if [[ $line == @* ]]; then |
| 50 |
printf '%s\n' "$line" |
| 51 |
fi |
| 52 |
done |
| 53 |
} |
| 54 |
|
| 55 |
__get_architectures() { |
| 56 |
systemd-analyze --no-legend --no-pager architectures 2>/dev/null | { while read -r a b; do echo " $a"; done; } |
| 57 |
} |
| 58 |
|
| 59 |
__get_filesystem_sets() { |
| 60 |
local line |
| 61 |
systemd-analyze filesystems --no-pager 2>/dev/null | while IFS= read -r line; do |
| 62 |
if [[ $line == @* ]]; then |
| 63 |
printf '%s\n' "$line" |
| 64 |
fi |
| 65 |
done |
| 66 |
} |
| 67 |
|
| 68 |
_systemd_analyze() { |
| 69 |
local i verb comps mode |
| 70 |
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword |
| 71 |
|
| 72 |
local -A OPTS=( |
| 73 |
[STANDALONE]='-h --help --version --system --user --global --order --require --no-pager |
| 74 |
--man=no --generators=yes -q --quiet' |
| 75 |
[ARG]='-H --host -M --machine --fuzz --from-pattern --to-pattern --root --debugger |
| 76 |
-A --debugger-arguments' |
| 77 |
) |
| 78 |
|
| 79 |
local -A VERBS=( |
| 80 |
[STANDALONE]='time blame unit-files unit-paths exit-status compare-versions timestamp timespan pcrs nvpcrs srk has-tpm2 identify-tpm2 smbios11 chid image-policy' |
| 81 |
[CRITICAL_CHAIN]='critical-chain' |
| 82 |
[DOT]='dot' |
| 83 |
[DUMP]='dump' |
| 84 |
[VERIFY]='verify' |
| 85 |
[SECCOMP_FILTER]='syscall-filter' |
| 86 |
[CAT_CONFIG]='cat-config' |
| 87 |
[SECURITY]='security' |
| 88 |
[CONDITION]='condition' |
| 89 |
[INSPECT_ELF]='inspect-elf' |
| 90 |
[DLOPEN_METADATA]='dlopen-metadata' |
| 91 |
[PLOT]='plot' |
| 92 |
[ARCHITECTURES]='architectures' |
| 93 |
[FDSTORE]='fdstore' |
| 94 |
[CAPABILITY]='capability' |
| 95 |
[TRANSIENT_SETTINGS]='transient-settings' |
| 96 |
[UNIT_SHELL]='unit-shell' |
| 97 |
[UNIT_GDB]='unit-gdb' |
| 98 |
[FILESYSTEMS]='filesystems' |
| 99 |
[CALENDAR]='calendar' |
| 100 |
) |
| 101 |
|
| 102 |
local CONFIGS='locale.conf systemd/bootchart.conf systemd/coredump.conf systemd/journald.conf |
| 103 |
systemd/journal-remote.conf systemd/journal-upload.conf systemd/logind.conf |
| 104 |
systemd/resolved.conf systemd/networkd.conf systemd/pstore.conf systemd/resolved.conf |
| 105 |
systemd/sleep.conf systemd/system.conf systemd/timedated.conf |
| 106 |
systemd/timesyncd.conf systemd/user.conf udev/udev.conf' |
| 107 |
|
| 108 |
_init_completion || return |
| 109 |
|
| 110 |
for ((i=0; i < COMP_CWORD; i++)); do |
| 111 |
if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} && |
| 112 |
! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then |
| 113 |
verb=${COMP_WORDS[i]} |
| 114 |
break |
| 115 |
fi |
| 116 |
done |
| 117 |
|
| 118 |
if __contains_word "--user" ${COMP_WORDS[*]}; then |
| 119 |
mode=--user |
| 120 |
else |
| 121 |
mode=--system |
| 122 |
fi |
| 123 |
|
| 124 |
if __contains_word "$prev" ${OPTS[ARG]}; then |
| 125 |
case $prev in |
| 126 |
--host|-H) |
| 127 |
comps=$(compgen -A hostname) |
| 128 |
;; |
| 129 |
--machine|-M) |
| 130 |
comps=$( __get_machines ) |
| 131 |
;; |
| 132 |
--debugger) |
| 133 |
comps="gdb lldb" |
| 134 |
;; |
| 135 |
*) |
| 136 |
return 0 |
| 137 |
;; |
| 138 |
esac |
| 139 |
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
| 140 |
return 0 |
| 141 |
fi |
| 142 |
|
| 143 |
if [[ -z ${verb-} && $cur = -* ]]; then |
| 144 |
COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) |
| 145 |
return 0 |
| 146 |
fi |
| 147 |
|
| 148 |
if [[ -z ${verb-} ]]; then |
| 149 |
comps=${VERBS[*]} |
| 150 |
|
| 151 |
elif __contains_word "$verb" ${VERBS[STANDALONE]}; then |
| 152 |
if [[ $cur = -* ]]; then |
| 153 |
comps='--help --version --system --user --global --no-pager' |
| 154 |
fi |
| 155 |
|
| 156 |
elif __contains_word "$verb" ${VERBS[CRITICAL_CHAIN]}; then |
| 157 |
if [[ $cur = -* ]]; then |
| 158 |
comps='--help --version --system --user --fuzz --no-pager' |
| 159 |
else |
| 160 |
comps=$( __get_units_all $mode ) |
| 161 |
fi |
| 162 |
|
| 163 |
elif __contains_word "$verb" ${VERBS[DOT]}; then |
| 164 |
if [[ $cur = -* ]]; then |
| 165 |
comps='--help --version --system --user --global --from-pattern --to-pattern --order --require' |
| 166 |
fi |
| 167 |
|
| 168 |
elif __contains_word "$verb" ${VERBS[DUMP]}; then |
| 169 |
if [[ $cur = -* ]]; then |
| 170 |
comps='--help --version --system --user --no-pager' |
| 171 |
else |
| 172 |
comps=$( __get_units_all $mode ) |
| 173 |
fi |
| 174 |
|
| 175 |
elif __contains_word "$verb" ${VERBS[SECCOMP_FILTER]}; then |
| 176 |
if [[ $cur = -* ]]; then |
| 177 |
comps='--help --version --no-pager' |
| 178 |
else |
| 179 |
comps=$( __get_syscall_sets ) |
| 180 |
fi |
| 181 |
|
| 182 |
elif __contains_word "$verb" ${VERBS[VERIFY]}; then |
| 183 |
if [[ $cur = -* ]]; then |
| 184 |
comps='--help --version --system --user --global --man=no --generators=yes --root --image --recursive-errors=no --recursive-errors=yes --recursive-errors=one' |
| 185 |
else |
| 186 |
comps=$( compgen -A file -- "$cur" |
| 187 |
__get_units_all $mode ) |
| 188 |
compopt -o filenames |
| 189 |
fi |
| 190 |
|
| 191 |
elif __contains_word "$verb" ${VERBS[CAT_CONFIG]}; then |
| 192 |
if [[ $cur = -* ]]; then |
| 193 |
comps='--help --version --root --no-pager' |
| 194 |
elif [[ -z $cur ]]; then |
| 195 |
comps="$CONFIGS" |
| 196 |
compopt -o filenames |
| 197 |
else |
| 198 |
comps="$CONFIGS $( compgen -A file -- "$cur" )" |
| 199 |
compopt -o filenames |
| 200 |
fi |
| 201 |
|
| 202 |
elif __contains_word "$verb" ${VERBS[SECURITY]}; then |
| 203 |
if [[ $cur = -* ]]; then |
| 204 |
comps='--help --version --no-pager --system --user -H --host -M --machine --offline --threshold --security-policy --json=off --json=pretty --json=short --root --image --profile=default --profile=nonetwork --profile=strict --profile=trusted' |
| 205 |
elif ! __contains_word "--offline" ${COMP_WORDS[*]}; then |
| 206 |
comps=$( __get_services $mode ) |
| 207 |
else |
| 208 |
comps="$CONFIGS $( compgen -A file -- "$cur" )" |
| 209 |
compopt -o filenames |
| 210 |
fi |
| 211 |
|
| 212 |
elif __contains_word "$verb" ${VERBS[CONDITION]}; then |
| 213 |
if [[ $cur = -* ]]; then |
| 214 |
comps='--help --version --system --user --global --no-pager --root --image' |
| 215 |
elif [[ $prev = "-u" ]] || [[ $prev = "--unit" ]]; then |
| 216 |
comps=$( __get_services $mode ) |
| 217 |
fi |
| 218 |
|
| 219 |
elif __contains_word "$verb" ${VERBS[INSPECT_ELF]}; then |
| 220 |
if [[ $cur = -* ]]; then |
| 221 |
comps='--help --version --json=off --json=pretty --json=short' |
| 222 |
else |
| 223 |
comps=$( compgen -A file -- "$cur" ) |
| 224 |
compopt -o filenames |
| 225 |
fi |
| 226 |
|
| 227 |
elif __contains_word "$verb" ${VERBS[DLOPEN_METADATA]}; then |
| 228 |
if [[ $cur = -* ]]; then |
| 229 |
comps='--help --version --json=off --json=pretty --json=short' |
| 230 |
else |
| 231 |
comps=$( compgen -A file -- "$cur" ) |
| 232 |
compopt -o filenames |
| 233 |
fi |
| 234 |
|
| 235 |
elif __contains_word "$verb" ${VERBS[PLOT]}; then |
| 236 |
if [[ $cur = -* ]]; then |
| 237 |
comps='--help --version --system --user --global --no-pager --json=off --json=pretty --json=short --table --no-legend --scale-svg --detailed' |
| 238 |
fi |
| 239 |
|
| 240 |
elif __contains_word "$verb" ${VERBS[ARCHITECTURES]}; then |
| 241 |
if [[ $cur = -* ]]; then |
| 242 |
comps='--help --version --no-pager --json=off --json=pretty --json=short --no-legend' |
| 243 |
else |
| 244 |
comps=$( __get_architectures ) |
| 245 |
fi |
| 246 |
|
| 247 |
elif __contains_word "$verb" ${VERBS[FDSTORE]}; then |
| 248 |
if [[ $cur = -* ]]; then |
| 249 |
comps='--help --version --system --user --global -H --host -M --machine --no-pager --json=off --json=pretty --json=short --root --image' |
| 250 |
else |
| 251 |
comps=$( __get_services $mode ) |
| 252 |
fi |
| 253 |
|
| 254 |
elif __contains_word "$verb" ${VERBS[CAPABILITY]}; then |
| 255 |
if [[ $cur = -* ]]; then |
| 256 |
comps='--help --version --no-pager --json=off --json=pretty --json=short -m --mask' |
| 257 |
fi |
| 258 |
|
| 259 |
elif __contains_word "$verb" ${VERBS[TRANSIENT_SETTINGS]}; then |
| 260 |
if [[ $cur = -* ]]; then |
| 261 |
comps='--help --version --no-pager' |
| 262 |
else |
| 263 |
comps="$(systemctl --no-legend --no-pager -t help)" |
| 264 |
fi |
| 265 |
|
| 266 |
elif __contains_word "$verb" ${VERBS[UNIT_SHELL]}; then |
| 267 |
if [[ $cur = -* ]]; then |
| 268 |
comps='--help --version' |
| 269 |
else |
| 270 |
comps=$( __get_services $mode ) |
| 271 |
fi |
| 272 |
|
| 273 |
elif __contains_word "$verb" ${VERBS[UNIT_GDB]}; then |
| 274 |
if [[ $cur = -* ]]; then |
| 275 |
comps='--help --version --debugger --debugger-arguments --root' |
| 276 |
else |
| 277 |
comps=$( __get_services $mode ) |
| 278 |
fi |
| 279 |
|
| 280 |
elif __contains_word "$verb" ${VERBS[FILESYSTEMS]}; then |
| 281 |
if [[ $cur = -* ]]; then |
| 282 |
comps='--help --version --no-pager' |
| 283 |
else |
| 284 |
comps=$( __get_filesystem_sets ) |
| 285 |
fi |
| 286 |
|
| 287 |
elif __contains_word "$verb" ${VERBS[CALENDAR]}; then |
| 288 |
if [[ $cur = -* ]]; then |
| 289 |
comps='--help --version --iterations --base-time' |
| 290 |
fi |
| 291 |
fi |
| 292 |
|
| 293 |
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
| 294 |
return 0 |
| 295 |
} |
| 296 |
|
| 297 |
complete -F _systemd_analyze systemd-analyze |