# systemctl(1) completion -*- shell-script -*-
-# SPDX-License-Identifier: LGPL-2.1+
+# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is part of systemd.
#
__systemctl() {
local mode=$1; shift 1
- systemctl $mode --full --no-legend --no-pager "$@" 2>/dev/null
+ systemctl $mode --full --no-legend --no-pager --plain "$@" 2>/dev/null
}
__systemd_properties() {
__get_machines() {
local a b
- { machinectl list-images --no-legend --no-pager; machinectl list --no-legend --no-pager; } | \
+ { machinectl list-images --full --no-legend --no-pager; machinectl list --full --no-legend --no-pager; } | \
{ while read a b; do echo " $a"; done; }
}
_systemctl () {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
- local cur_orig=$cur
- local i verb comps mode
+ local i verb comps mode cur_orig
local -A OPTS=(
[STANDALONE]='--all -a --reverse --after --before --defaults --force -f --full -l --global
--quiet -q --system --user --version --runtime --recursive -r --firmware-setup
--show-types -i --ignore-inhibitors --plain --failed --value --fail --dry-run --wait'
[ARG]='--host -H --kill-who --property -p --signal -s --type -t --state --job-mode --root
- --preset-mode -n --lines -o --output -M --machine --message'
+ --preset-mode -n --lines -o --output -M --machine --message --timestamp'
)
if __contains_word "--user" ${COMP_WORDS[*]}; then
--machine|-M)
comps=$( __get_machines )
;;
+ --timestamp)
+ comps='pretty us µs utc us+utc µs+utc'
+ ;;
esac
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
[FILE]='link switch-root'
[TARGETS]='set-default'
[MACHINES]='list-machines'
+ [LOG_LEVEL]='log-level'
+ [LOG_TARGET]='log-target'
+ [SERVICE_WATCHDOGS]='service-watchdogs'
)
for ((i=0; i < COMP_CWORD; i++)); do
done
# When trying to match a unit name with certain special characters in its name (i.e
- # foo\x2dbar:01) they get escaped by bash along the way, thus causing any possible
- # match to fail. Let's unescape such characters in the verb we're trying to
- # autocomplete to avoid this, however, use the original verb (cur_orig)
- # during the final match (COMPREPLY)
- cur="$(echo $cur | xargs echo)"
+ # foo\x2dbar:01) they get (un)escaped by bash along the way, thus causing any possible
+ # match to fail.
+ # The following condition solves two cases:
+ # 1) We're trying to complete an already escaped unit name part,
+ # i.e foo\\x2dba. In this case we need to unescape the name, so it
+ # gets properly matched with the systemctl output (i.e. foo\x2dba).
+ # However, we need to keep the original escaped name as well for the
+ # final match, as the completion machinery does the unescaping
+ # automagically.
+ # 2) We're trying to complete an unescaped (literal) unit name part,
+ # i.e. foo\x2dba. That means we don't have to do the unescaping
+ # required for correct matching with systemctl's output, however,
+ # we need to escape the name for the final match, where the completion
+ # expects the string to be escaped.
+ cur_orig=$cur
+ if [[ $cur =~ '\\' ]]; then
+ cur="$(echo $cur | xargs echo)"
+ else
+ cur_orig="$(printf '%q' $cur)"
+ fi
if [[ -z $verb ]]; then
comps="${VERBS[*]}"
elif __contains_word "$verb" ${VERBS[TARGETS]}; then
comps=$( __systemctl $mode list-unit-files --type target --full --all "$cur*" \
| { while read -r a b; do echo " $a"; done; } )
+ elif __contains_word "$verb" ${VERBS[LOG_LEVEL]}; then
+ comps='debug info notice warning err crit alert emerg'
+ elif __contains_word "$verb" ${VERBS[LOG_TARGET]}; then
+ comps='console journal kmsg journal-or-kmsg null'
+ elif __contains_word "$verb" ${VERBS[SERVICE_WATCHDOGS]}; then
+ comps='on off'
fi
COMPREPLY=( $(compgen -o filenames -W '$comps' -- "$cur_orig") )