]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut-bash-completion.sh
style: shfmt post reformat
[thirdparty/dracut.git] / dracut-bash-completion.sh
CommitLineData
fb7b8be8 1#!/bin/bash
917f3e4d
HH
2# Copyright 2013 Red Hat, Inc. All rights reserved.
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
17
9a52c3fd
HH
18__contains_word() {
19 local word="$1"
20 shift
75d758e8 21 for w in "$@"; do [[ $w == "$word" ]] && return 0; done
9a52c3fd 22 return 1
917f3e4d
HH
23}
24
25_dracut() {
9a52c3fd
HH
26 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD - 1]}
27 local -A OPTS=(
28 [STANDALONE]='-f -v -q -l -H -h -M -N
2b50b67c
HH
29 --ro-mnt --force --kernel-only --no-kernel --strip --nostrip
30 --hardlink --nohardlink --noprefix --mdadmconf --nomdadmconf
31 --lvmconf --nolvmconf --debug --profile --verbose --quiet
32 --local --hostonly --no-hostonly --fstab --help --bzip2 --lzma
33 --xz --zstd --no-compress --gzip --list-modules --show-modules --keep
34 --printsize --regenerate-all --noimageifnotneeded --early-microcode
35 --no-early-microcode --print-cmdline --reproducible --uefi'
9a52c3fd 36 [ARG]='-a -m -o -d -I -k -c -L --kver --add --force-add --add-drivers
2b50b67c
HH
37 --omit-drivers --modules --omit --drivers --filesystems --install
38 --fwdir --libdirs --fscks --add-fstab --mount --device --nofscks
39 --kmoddir --conf --confdir --tmpdir --stdlog --compress --prefix
40 --kernel-cmdline --sshkey --persistent-policy --install-optional
41 --loginstall --uefi-stub --kernel-image
42 '
9a52c3fd 43 )
917f3e4d 44
9a52c3fd
HH
45 # shellcheck disable=SC2086
46 if __contains_word "$prev" ${OPTS[ARG]}; then
47 case $prev in
48 --kmoddir | -k | --fwdir | --confdir | --tmpdir)
49 comps=$(compgen -d -- "$cur")
50 compopt -o filenames
51 ;;
52 -c | --conf | --sshkey | --add-fstab | --add-device | -I | --install | --install-optional)
53 comps=$(compgen -f -- "$cur")
54 compopt -o filenames
55 ;;
56 -a | -m | -o | --add | --modules | --omit)
57 comps=$(dracut --list-modules 2> /dev/null)
58 ;;
59 --persistent-policy)
60 comps=$(
61 cd /dev/disk/ || return 0
62 printf -- "%s " *
63 )
64 ;;
65 --kver)
66 comps=$(
67 cd /lib/modules || return 0
68 echo [0-9]*
69 )
70 ;;
71 *)
917f3e4d 72 return 0
9a52c3fd
HH
73 ;;
74 esac
75 # shellcheck disable=SC2207
76 # shellcheck disable=SC2016
77 COMPREPLY=($(compgen -W '$comps' -- "$cur"))
78 return 0
79 fi
917f3e4d 80
75d758e8 81 if [[ $cur == -* ]]; then
9a52c3fd
HH
82 # shellcheck disable=SC2207
83 # shellcheck disable=SC2016
84 COMPREPLY=($(compgen -W '${OPTS[*]}' -- "$cur"))
85 return 0
86 fi
952c2e4e 87
9a52c3fd
HH
88 local args
89 _count_args
90 if [[ $args -eq 1 ]]; then
91 _filedir
92 return 0
93 elif [[ $args -eq 2 ]]; then
94 # shellcheck disable=SC2034
95 comps=$(
96 cd /lib/modules || return 0
97 echo [0-9]*
98 )
99 # shellcheck disable=SC2207
100 # shellcheck disable=SC2016
101 COMPREPLY=($(compgen -W '$comps' -- "$cur"))
102 return 0
103 fi
917f3e4d
HH
104}
105
106complete -F _dracut dracut