1 # kmod completion -*- shell-script -*-
3 # This file is part of systemd.
5 # Copyright 2010 Ran Benita
6 # Copyright (C) 2013 Intel Corporation. All rights reserved.
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.
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.
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/>.
23 for w in "$@"; do [[ "$w" = "$word" ]] && return 0; done
28 local prevprev=${COMP_WORDS[COMP_CWORD-2]}
29 local short="$1" long="$2"
31 if [[ "$prev" = "$short" || "$prev" = "$long" ]]; then
32 declare -g cur=${cur#=}
34 elif [[ "$prev" = "=" && "$prevprev" = "$long" ]]; then
41 _kmod_static_nodes () {
42 local OPTS='-o -f -h --help'
43 local OPTS_EQUAL='--output --format'
44 local GROUP_FORMAT='human tmpfiles devname'
46 if __is_opt '-o' '--output'; then
48 COMPREPLY=( $(compgen -f -- "$cur") )
50 elif __is_opt '-f' '--format'; then
51 COMPREPLY=( $(compgen -W "$GROUP_FORMAT" -- "$cur" ) )
55 local cur=${COMP_WORDS[COMP_CWORD]}
58 COMPREPLY=( $(compgen -W "$OPTS" -- "$cur") )
59 COMPREPLY+=( $(compgen -W "$OPTS_EQUAL" -S= -- "$cur") )
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'
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
76 for ((i=0; $i <= $COMP_CWORD; i++)); do
77 if __contains_word "${COMP_WORDS[i]}" "${VERBS[@]}"; then
83 if [[ -z $verb ]]; then
84 COMPREPLY=( $(compgen -W '${OPTS[*]} ${VERBS[*]}' -- "$cur") )
88 local func=${verb//-/_}
90 if declare -F _kmod_${func} > /dev/null; then
94 # allow the space if there's only one completion and it doesn't end with
96 if [[ ${#COMPREPLY[@]} == 1 && ${COMPREPLY[0]} != *"=" ]] ; then
103 complete -F _kmod kmod