| 1 |
# shellcheck shell=bash |
| 2 |
# bootctl(1) completion -*- shell-script -*- |
| 3 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
# |
| 5 |
# This file is part of systemd. |
| 6 |
# |
| 7 |
# systemd is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU Lesser General Public License as published by |
| 9 |
# the Free Software Foundation; either version 2.1 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# systemd is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
# General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU Lesser General Public License |
| 18 |
# along with systemd; If not, see <https://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
__contains_word () { |
| 21 |
local w word=$1; shift |
| 22 |
for w in "$@"; do |
| 23 |
[[ $w = "$word" ]] && return |
| 24 |
done |
| 25 |
} |
| 26 |
|
| 27 |
__get_entry_ids() { |
| 28 |
bootctl --no-pager list 2>/dev/null | { while read -r a b; do [[ $a == 'id:' ]] && echo " $b"; done; } |
| 29 |
} |
| 30 |
|
| 31 |
_bootctl() { |
| 32 |
local i verb comps |
| 33 |
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} |
| 34 |
local -A OPTS=( |
| 35 |
[STANDALONE]='-h --help --version |
| 36 |
-p --print-esp-path -x --print-boot-path --print-loader-path |
| 37 |
--print-stub-path -R --print-root-device -RR |
| 38 |
--print-efi-architecture |
| 39 |
--no-pager --graceful -q --quiet --all-architectures |
| 40 |
--dry-run' |
| 41 |
[ARG]='--esp-path --boot-path --root --image --image-policy --install-source |
| 42 |
--variables --random-seed --make-entry-directory --entry-token --json |
| 43 |
--efi-boot-option-description --efi-boot-option-description-with-device |
| 44 |
--secure-boot-auto-enroll --private-key |
| 45 |
--private-key-source --certificate --certificate-source |
| 46 |
--oldest --keep-free --entry-title --entry-version --entry-commit |
| 47 |
-X --extra --tries-left' |
| 48 |
) |
| 49 |
|
| 50 |
if __contains_word "$prev" ${OPTS[ARG]}; then |
| 51 |
case $prev in |
| 52 |
--esp-path|--boot-path|--private-key|--certificate) |
| 53 |
if [[ -z $cur ]]; then |
| 54 |
comps=$(compgen -A directory -- "/" ) |
| 55 |
else |
| 56 |
comps=$(compgen -A directory -- "$cur" ) |
| 57 |
fi |
| 58 |
compopt -o filenames |
| 59 |
;; |
| 60 |
--make-entry-directory) |
| 61 |
comps="yes no auto" |
| 62 |
;; |
| 63 |
--entry-token) |
| 64 |
comps="machine-id os-id os-image-id auto literal:" |
| 65 |
;; |
| 66 |
--image|--root|-X|--extra) |
| 67 |
compopt -o nospace |
| 68 |
comps=$( compgen -A file -- "$cur" ) |
| 69 |
;; |
| 70 |
--install-source) |
| 71 |
comps="image host auto" |
| 72 |
;; |
| 73 |
--random-seed|--variables|--secure-boot-auto-enroll|--oldest|--efi-boot-option-description-with-device) |
| 74 |
comps="yes no" |
| 75 |
;; |
| 76 |
--json) |
| 77 |
comps=$( bootctl --json=help 2>/dev/null ) |
| 78 |
;; |
| 79 |
esac |
| 80 |
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
| 81 |
return 0 |
| 82 |
fi |
| 83 |
|
| 84 |
if [[ "$cur" = -* ]]; then |
| 85 |
COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) |
| 86 |
return 0 |
| 87 |
fi |
| 88 |
|
| 89 |
local -A VERBS=( |
| 90 |
[STANDALONE]='help status install update remove is-installed random-seed list set-timeout set-timeout-oneshot cleanup' |
| 91 |
[BOOTENTRY]='set-default set-oneshot set-sysfail set-preferred unlink' |
| 92 |
[BOOLEAN]='reboot-to-firmware' |
| 93 |
[FILE]='kernel-identify kernel-inspect link' |
| 94 |
) |
| 95 |
|
| 96 |
for ((i=0; i < COMP_CWORD; i++)); do |
| 97 |
if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then |
| 98 |
verb=${COMP_WORDS[i]} |
| 99 |
break |
| 100 |
fi |
| 101 |
done |
| 102 |
|
| 103 |
if [[ -z ${verb-} ]]; then |
| 104 |
comps=${VERBS[*]} |
| 105 |
elif __contains_word "$verb" ${VERBS[STANDALONE]}; then |
| 106 |
comps='' |
| 107 |
elif __contains_word "$verb" ${VERBS[BOOTENTRY]}; then |
| 108 |
name= |
| 109 |
for ((i++; i < COMP_CWORD; i++)); do |
| 110 |
if ! __contains_word "${COMP_WORDS[i]}" ${OPTS[*]} ${VERBS[*]} && |
| 111 |
! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then |
| 112 |
name=${COMP_WORDS[i]} |
| 113 |
break |
| 114 |
fi |
| 115 |
done |
| 116 |
|
| 117 |
if [[ -z $name ]]; then |
| 118 |
comps=$( __get_entry_ids ) |
| 119 |
else |
| 120 |
comps='' |
| 121 |
fi |
| 122 |
elif __contains_word "$verb" ${VERBS[BOOLEAN]}; then |
| 123 |
comps="yes no" |
| 124 |
elif __contains_word "$verb" ${VERBS[FILE]}; then |
| 125 |
comps=$( compgen -A file -- "$cur" ) |
| 126 |
compopt -o filenames |
| 127 |
fi |
| 128 |
|
| 129 |
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
| 130 |
return 0 |
| 131 |
} |
| 132 |
|
| 133 |
complete -F _bootctl bootctl |