Debian Codegraph @

shell-completion/bash/systemd-sysinstall

raw
1 # shellcheck shell=bash
2 # systemd-sysinstall(8) 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_block_devices() {
28 systemd-repart --list-devices 2>/dev/null
29 }
30
31 _systemd_sysinstall() {
32 local comps
33 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
34 local -A OPTS=(
35 [STANDALONE]='-h --help --version'
36 [ARG]='--welcome
37 --chrome
38 --erase
39 --confirm
40 --summary
41 --reboot
42 --variables
43 --mute-console
44 --copy-locale
45 --copy-keymap
46 --copy-timezone
47 --definitions
48 --kernel
49 --set-credential
50 --load-credential'
51 )
52
53 _init_completion || return
54
55 if __contains_word "$prev" ${OPTS[ARG]}; then
56 case $prev in
57 --welcome|--chrome|--confirm|--summary|--reboot|--mute-console|--copy-locale|--copy-keymap|--copy-timezone)
58 comps='yes no'
59 ;;
60 --erase|--variables)
61 comps='yes no auto'
62 ;;
63 --definitions)
64 comps=$(compgen -A directory -- "$cur")
65 compopt -o filenames
66 ;;
67 --kernel|--load-credential)
68 comps=$(compgen -A file -- "$cur")
69 compopt -o filenames
70 ;;
71 --set-credential)
72 comps=''
73 ;;
74 esac
75 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
76 return 0
77 fi
78
79 if [[ "$cur" = -* ]]; then
80 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
81 return 0
82 fi
83
84 comps=$(__get_block_devices)
85 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
86 compopt -o filenames
87 return 0
88 }
89
90 complete -F _systemd_sysinstall systemd-sysinstall