]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/bootctl
hwdb: Add accelerometer orientation quirk for the PoV TAB-P1006W-232-3G
[thirdparty/systemd.git] / shell-completion / bash / bootctl
1 # bootctl(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
3 #
4 # This file is part of systemd.
5 #
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 <http://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 --no-variables -p --print-path --version --no-pager'
36 [ARG]='--path'
37 )
38
39 if __contains_word "$prev" ${OPTS[ARG]}; then
40 case $prev in
41 --path)
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 ;;
49 esac
50 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
51 return 0
52 fi
53
54 if [[ "$cur" = -* ]]; then
55 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
56 return 0
57 fi
58
59 local -A VERBS=(
60 [STANDALONE]='help install list remove status update'
61 [BOOTENTRY]='set-default set-oneshot'
62 )
63
64 for ((i=0; i < COMP_CWORD; i++)); do
65 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
66 verb=${COMP_WORDS[i]}
67 break
68 fi
69 done
70
71 if [[ -z $verb ]]; then
72 comps=${VERBS[*]}
73 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
74 comps=''
75 elif __contains_word "$verb" ${VERBS[BOOTENTRY]}; then
76 name=
77 for ((i++; i < COMP_CWORD; i++)); do
78 if ! __contains_word "${COMP_WORDS[i]}" ${OPTS[*]} ${VERBS[*]} &&
79 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
80 name=${COMP_WORDS[i]}
81 break;
82 fi
83 done
84
85 if [[ -z $name ]]; then
86 comps=$( __get_entry_ids )
87 else
88 comps=''
89 fi
90 fi
91
92 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
93 return 0
94 }
95
96 complete -F _bootctl bootctl