1 # shellcheck shell=bash
2 # bootctl(1) completion -*- shell-script -*-
3 # SPDX-License-Identifier: LGPL-2.1-or-later
5 # This file is part of systemd.
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.
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.
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/>.
21 local w word=$1; shift
23 [[ $w = "$word" ]] && return
28 bootctl --no-pager list 2>/dev/null | { while read -r a b; do [[ $a == 'id:' ]] && echo " $b"; done }
33 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
35 [STANDALONE]='-h --help -p --print-esp-path -x --print-boot-path --version --no-variables --no-pager --graceful --dry-run'
36 [ARG]='--esp-path --boot-path --make-machine-id-directory --root --image --install-source'
39 if __contains_word "$prev" ${OPTS[ARG]}; then
41 --esp-path|--boot-path)
42 if [[ -z $cur ]]; then
43 comps=$(compgen -A directory -- "/" )
45 comps=$(compgen -A directory -- "$cur" )
49 --make-machine-id-directory)
54 comps=$( compgen -A file -- "$cur" )
57 comps="image host auto"
60 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
64 if [[ "$cur" = -* ]]; then
65 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
70 # systemd-efi-options takes an argument, but it is free-form, so we cannot complete it
71 [STANDALONE]='help status install update remove is-installed random-seed systemd-efi-options list set-timeout set-timeout-oneshot cleanup'
72 [BOOTENTRY]='set-default set-oneshot unlink'
73 [BOOLEAN]='reboot-to-firmware'
76 for ((i=0; i < COMP_CWORD; i++)); do
77 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
83 if [[ -z ${verb-} ]]; then
85 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
87 elif __contains_word "$verb" ${VERBS[BOOTENTRY]}; then
89 for ((i++; i < COMP_CWORD; i++)); do
90 if ! __contains_word "${COMP_WORDS[i]}" ${OPTS[*]} ${VERBS[*]} &&
91 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
97 if [[ -z $name ]]; then
98 comps=$( __get_entry_ids )
102 elif __contains_word "$verb" ${VERBS[BOOLEAN]}; then
106 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
110 complete -F _bootctl bootctl