]>
Commit | Line | Data |
---|---|---|
f8457290 | 1 | # shellcheck shell=bash |
95fe27d9 | 2 | # bootctl(1) completion -*- shell-script -*- |
db9ecf05 | 3 | # SPDX-License-Identifier: LGPL-2.1-or-later |
95fe27d9 TA |
4 | # |
5 | # This file is part of systemd. | |
6 | # | |
95fe27d9 TA |
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 | |
85fce6f4 | 18 | # along with systemd; If not, see <https://www.gnu.org/licenses/>. |
95fe27d9 TA |
19 | |
20 | __contains_word () { | |
843cfcb1 ZJS |
21 | local w word=$1; shift |
22 | for w in "$@"; do | |
23 | [[ $w = "$word" ]] && return | |
24 | done | |
95fe27d9 TA |
25 | } |
26 | ||
a73b2f4a | 27 | __get_entry_ids() { |
843cfcb1 | 28 | bootctl --no-pager list 2>/dev/null | { while read -r a b; do [[ $a == 'id:' ]] && echo " $b"; done } |
a73b2f4a YW |
29 | } |
30 | ||
95fe27d9 | 31 | _bootctl() { |
843cfcb1 ZJS |
32 | local i verb comps |
33 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} | |
34 | local -A OPTS=( | |
8702496b | 35 | [STANDALONE]='-h --help -p --print-esp-path -x --print-boot-path --version --no-variables --no-pager --graceful --dry-run' |
02d06ba1 | 36 | [ARG]='--esp-path --boot-path --make-machine-id-directory --root --image --install-source' |
843cfcb1 | 37 | ) |
95fe27d9 | 38 | |
843cfcb1 ZJS |
39 | if __contains_word "$prev" ${OPTS[ARG]}; then |
40 | case $prev in | |
2789437b | 41 | --esp-path|--boot-path) |
843cfcb1 ZJS |
42 | if [[ -z $cur ]]; then |
43 | comps=$(compgen -A directory -- "/" ) | |
44 | else | |
45 | comps=$(compgen -A directory -- "$cur" ) | |
46 | fi | |
47 | compopt -o filenames | |
48 | ;; | |
f1c70ed1 NK |
49 | --make-machine-id-directory) |
50 | comps="yes no auto" | |
51 | ;; | |
80a2381d LB |
52 | --image|--root) |
53 | compopt -o nospace | |
54 | comps=$( compgen -A file -- "$cur" ) | |
55 | ;; | |
02d06ba1 LB |
56 | --install-source) |
57 | comps="image host auto" | |
58 | ;; | |
843cfcb1 ZJS |
59 | esac |
60 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
61 | return 0 | |
62 | fi | |
ed0c5a6f | 63 | |
843cfcb1 ZJS |
64 | if [[ "$cur" = -* ]]; then |
65 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
66 | return 0 | |
67 | fi | |
95fe27d9 | 68 | |
843cfcb1 | 69 | local -A VERBS=( |
8f0a346a | 70 | # systemd-efi-options takes an argument, but it is free-form, so we cannot complete it |
8702496b LN |
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' | |
8f0a346a | 73 | [BOOLEAN]='reboot-to-firmware' |
843cfcb1 | 74 | ) |
95fe27d9 | 75 | |
843cfcb1 ZJS |
76 | for ((i=0; i < COMP_CWORD; i++)); do |
77 | if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then | |
78 | verb=${COMP_WORDS[i]} | |
79 | break | |
80 | fi | |
81 | done | |
95fe27d9 | 82 | |
36ec0268 | 83 | if [[ -z ${verb-} ]]; then |
843cfcb1 ZJS |
84 | comps=${VERBS[*]} |
85 | elif __contains_word "$verb" ${VERBS[STANDALONE]}; then | |
86 | comps='' | |
87 | elif __contains_word "$verb" ${VERBS[BOOTENTRY]}; then | |
88 | name= | |
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 | |
92 | name=${COMP_WORDS[i]} | |
93 | break; | |
94 | fi | |
95 | done | |
a73b2f4a | 96 | |
843cfcb1 ZJS |
97 | if [[ -z $name ]]; then |
98 | comps=$( __get_entry_ids ) | |
99 | else | |
100 | comps='' | |
95fe27d9 | 101 | fi |
8f0a346a ZJS |
102 | elif __contains_word "$verb" ${VERBS[BOOLEAN]}; then |
103 | comps="yes no" | |
843cfcb1 | 104 | fi |
95fe27d9 | 105 | |
843cfcb1 ZJS |
106 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
107 | return 0 | |
95fe27d9 TA |
108 | } |
109 | ||
110 | complete -F _bootctl bootctl |