]> git.ipfire.org Git - thirdparty/systemd.git/blame - shell-completion/bash/bootctl
Merge pull request #12619 from zachsmith/refactor-parse-sleep-config
[thirdparty/systemd.git] / shell-completion / bash / bootctl
CommitLineData
95fe27d9 1# bootctl(1) completion -*- shell-script -*-
7059062c 2# SPDX-License-Identifier: LGPL-2.1+
95fe27d9
TA
3#
4# This file is part of systemd.
5#
95fe27d9
TA
6# systemd is free software; you can redistribute it and/or modify it
7# under the terms of the GNU Lesser General Public License as published by
8# the Free Software Foundation; either version 2.1 of the License, or
9# (at your option) any later version.
10#
11# systemd is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public License
17# along with systemd; If not, see <http://www.gnu.org/licenses/>.
18
19__contains_word () {
843cfcb1
ZJS
20 local w word=$1; shift
21 for w in "$@"; do
22 [[ $w = "$word" ]] && return
23 done
95fe27d9
TA
24}
25
a73b2f4a 26__get_entry_ids() {
843cfcb1 27 bootctl --no-pager list 2>/dev/null | { while read -r a b; do [[ $a == 'id:' ]] && echo " $b"; done }
a73b2f4a
YW
28}
29
95fe27d9 30_bootctl() {
843cfcb1
ZJS
31 local i verb comps
32 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
33 local -A OPTS=(
2789437b
YW
34 [STANDALONE]='-h --help --no-variables -p --print-esp-path -x --print-boot-path --version --no-pager'
35 [ARG]='--esp-path --boot-path'
843cfcb1 36 )
95fe27d9 37
843cfcb1
ZJS
38 if __contains_word "$prev" ${OPTS[ARG]}; then
39 case $prev in
2789437b 40 --esp-path|--boot-path)
843cfcb1
ZJS
41 if [[ -z $cur ]]; then
42 comps=$(compgen -A directory -- "/" )
43 else
44 comps=$(compgen -A directory -- "$cur" )
45 fi
46 compopt -o filenames
47 ;;
48 esac
49 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
50 return 0
51 fi
ed0c5a6f 52
843cfcb1
ZJS
53 if [[ "$cur" = -* ]]; then
54 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
55 return 0
56 fi
95fe27d9 57
843cfcb1
ZJS
58 local -A VERBS=(
59 [STANDALONE]='help install list remove status update'
60 [BOOTENTRY]='set-default set-oneshot'
61 )
95fe27d9 62
843cfcb1
ZJS
63 for ((i=0; i < COMP_CWORD; i++)); do
64 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
65 verb=${COMP_WORDS[i]}
66 break
67 fi
68 done
95fe27d9 69
843cfcb1
ZJS
70 if [[ -z $verb ]]; then
71 comps=${VERBS[*]}
72 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
73 comps=''
74 elif __contains_word "$verb" ${VERBS[BOOTENTRY]}; then
75 name=
76 for ((i++; i < COMP_CWORD; i++)); do
77 if ! __contains_word "${COMP_WORDS[i]}" ${OPTS[*]} ${VERBS[*]} &&
78 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
79 name=${COMP_WORDS[i]}
80 break;
81 fi
82 done
a73b2f4a 83
843cfcb1
ZJS
84 if [[ -z $name ]]; then
85 comps=$( __get_entry_ids )
86 else
87 comps=''
95fe27d9 88 fi
843cfcb1 89 fi
95fe27d9 90
843cfcb1
ZJS
91 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
92 return 0
95fe27d9
TA
93}
94
95complete -F _bootctl bootctl