blob: 35e1040a0787ce8f94a241eb6c0cde9086607c9e [file] [log] [blame]
Lucas De Marchiac6573a2013-07-29 13:23:54 -03001# kmod completion -*- shell-script -*-
2#
3# This file is part of systemd.
4#
5# Copyright 2010 Ran Benita
6# Copyright (C) 2013 Intel Corporation. All rights reserved.
7#
8# systemd is free software; you can redistribute it and/or modify it
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#
13# systemd is distributed in the hope that it will be useful, but
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
19# along with systemd; If not, see <http://www.gnu.org/licenses/>.
20
21__contains_word () {
22 local word=$1; shift
23 for w in "$@"; do [[ "$w" = "$word" ]] && return 0; done
24 return 1
25}
26
Lucas De Marchiec6d0262013-07-30 03:28:41 -030027_kmod_static_nodes () {
28 local OPTS='-o --output -f --format -h --help'
29 local GROUP_FORMAT='human tmpfiles devname'
30
31 case "$prev" in
32 '-o' | '--output')
33 compopt -o filenames
34 COMPREPLY=( $(compgen -f -- "$cur") )
35 return 0
36 ;;
37 '-f' | '--format')
38 COMPREPLY=( $(compgen -W "$GROUP_FORMAT" -- "$cur" ) )
39 return 0
40 ;;
41 esac
42
43 COMPREPLY=( $(compgen -W "$OPTS" -- "$cur") )
44}
45
Lucas De Marchiac6573a2013-07-29 13:23:54 -030046_kmod() {
47 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
48 local VERBS=(help list static-nodes)
49 local OPTS='-h --help -V --version'
50 local verb
51
52 # standalone options, no other option or action allowed
53 for ((i=0; $i < $COMP_CWORD; i++)); do
54 if __contains_word "${COMP_WORDS[i]}" ${OPTS}; then
55 return 0
56 fi
57 done
58
59 # find the action
60 for ((i=0; $i <= $COMP_CWORD; i++)); do
61 if __contains_word "${COMP_WORDS[i]}" "${VERBS[@]}"; then
62 verb=${COMP_WORDS[i]}
63 break
64 fi
65 done
66
67 if [[ -z $verb ]]; then
68 COMPREPLY=( $(compgen -W '${OPTS[*]} ${VERBS[*]}' -- "$cur") )
69 return 0
70 fi
71
Lucas De Marchiec6d0262013-07-30 03:28:41 -030072 local func=${verb//-/_}
73
74 if declare -F _kmod_${func} > /dev/null; then
75 _kmod_${func}
76 fi
77
Lucas De Marchiac6573a2013-07-29 13:23:54 -030078 return 0
79}
80
81complete -F _kmod kmod