]> git.ipfire.org Git - thirdparty/kmod.git/blame - shell-completion/bash/kmod
Remove references to systemd from the bash completion file
[thirdparty/kmod.git] / shell-completion / bash / kmod
CommitLineData
ac6573aa
LDM
1# kmod completion -*- shell-script -*-
2#
1008a2d5 3# This file is part of kmod.
ac6573aa
LDM
4#
5# Copyright 2010 Ran Benita
6# Copyright (C) 2013 Intel Corporation. All rights reserved.
7#
1008a2d5 8# This program is free software; you can redistribute it and/or modify it
ac6573aa
LDM
9# under the terms of the GNU Lesser General Public License as published by
10# the Free Software Foundation; either version 2.1 of the License, or
11# (at your option) any later version.
12#
1008a2d5 13# This program is distributed in the hope that it will be useful, but
ac6573aa
LDM
14# WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# General Public License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public License
1008a2d5 19# along with this program; if not, see <http://www.gnu.org/licenses/>.
ac6573aa
LDM
20
21__contains_word () {
22 local word=$1; shift
23 for w in "$@"; do [[ "$w" = "$word" ]] && return 0; done
24 return 1
25}
26
48a40964
LDM
27__is_opt () {
28 local prevprev=${COMP_WORDS[COMP_CWORD-2]}
29 local short="$1" long="$2"
30
31 if [[ "$prev" = "$short" || "$prev" = "$long" ]]; then
32 declare -g cur=${cur#=}
33 return 0
34 elif [[ "$prev" = "=" && "$prevprev" = "$long" ]]; then
35 return 0
36 fi
37
38 return 1
39}
40
ec6d026f 41_kmod_static_nodes () {
48a40964
LDM
42 local OPTS='-o -f -h --help'
43 local OPTS_EQUAL='--output --format'
ec6d026f
LDM
44 local GROUP_FORMAT='human tmpfiles devname'
45
48a40964 46 if __is_opt '-o' '--output'; then
ec6d026f
LDM
47 compopt -o filenames
48 COMPREPLY=( $(compgen -f -- "$cur") )
49 return 0
48a40964 50 elif __is_opt '-f' '--format'; then
ec6d026f
LDM
51 COMPREPLY=( $(compgen -W "$GROUP_FORMAT" -- "$cur" ) )
52 return 0
48a40964 53 fi
ec6d026f 54
48a40964
LDM
55 local cur=${COMP_WORDS[COMP_CWORD]}
56
57 compopt -o nospace
ec6d026f 58 COMPREPLY=( $(compgen -W "$OPTS" -- "$cur") )
48a40964 59 COMPREPLY+=( $(compgen -W "$OPTS_EQUAL" -S= -- "$cur") )
ec6d026f
LDM
60}
61
ac6573aa
LDM
62_kmod() {
63 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
64 local VERBS=(help list static-nodes)
65 local OPTS='-h --help -V --version'
66 local verb
67
68 # standalone options, no other option or action allowed
69 for ((i=0; $i < $COMP_CWORD; i++)); do
70 if __contains_word "${COMP_WORDS[i]}" ${OPTS}; then
71 return 0
72 fi
73 done
74
75 # find the action
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
82
83 if [[ -z $verb ]]; then
84 COMPREPLY=( $(compgen -W '${OPTS[*]} ${VERBS[*]}' -- "$cur") )
85 return 0
86 fi
87
ec6d026f
LDM
88 local func=${verb//-/_}
89
90 if declare -F _kmod_${func} > /dev/null; then
91 _kmod_${func}
92 fi
93
48a40964
LDM
94 # allow the space if there's only one completion and it doesn't end with
95 # '='
96 if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} != *"=" ]] ; then
97 compopt +o nospace
98 fi
99
ac6573aa
LDM
100 return 0
101}
102
103complete -F _kmod kmod