kernel-install revision 819da59577758a7a328020546127091e45bc59e7
819da59577758a7a328020546127091e45bc59e7Kay Sievers# kernel-install(8) completion -*- shell-script -*-
819da59577758a7a328020546127091e45bc59e7Kay Sievers#
819da59577758a7a328020546127091e45bc59e7Kay Sievers# This file is part of systemd.
819da59577758a7a328020546127091e45bc59e7Kay Sievers#
819da59577758a7a328020546127091e45bc59e7Kay Sievers# Copyright 2013 Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers#
819da59577758a7a328020546127091e45bc59e7Kay Sievers# systemd is free software; you can redistribute it and/or modify it
819da59577758a7a328020546127091e45bc59e7Kay Sievers# under the terms of the GNU Lesser General Public License as published by
819da59577758a7a328020546127091e45bc59e7Kay Sievers# the Free Software Foundation; either version 2.1 of the License, or
819da59577758a7a328020546127091e45bc59e7Kay Sievers# (at your option) any later version.
819da59577758a7a328020546127091e45bc59e7Kay Sievers#
819da59577758a7a328020546127091e45bc59e7Kay Sievers# systemd is distributed in the hope that it will be useful, but
819da59577758a7a328020546127091e45bc59e7Kay Sievers# WITHOUT ANY WARRANTY; without even the implied warranty of
819da59577758a7a328020546127091e45bc59e7Kay Sievers# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
819da59577758a7a328020546127091e45bc59e7Kay Sievers# General Public License for more details.
819da59577758a7a328020546127091e45bc59e7Kay Sievers#
819da59577758a7a328020546127091e45bc59e7Kay Sievers# You should have received a copy of the GNU Lesser General Public License
819da59577758a7a328020546127091e45bc59e7Kay Sievers# along with systemd; If not, see <http://www.gnu.org/licenses/>.
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers__contains_word () {
819da59577758a7a328020546127091e45bc59e7Kay Sievers local word=$1; shift
819da59577758a7a328020546127091e45bc59e7Kay Sievers for w in $*; do [[ $w = $word ]] && return 0; done
819da59577758a7a328020546127091e45bc59e7Kay Sievers return 1
819da59577758a7a328020546127091e45bc59e7Kay Sievers}
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers_kernel_install() {
819da59577758a7a328020546127091e45bc59e7Kay Sievers local i verb comps
819da59577758a7a328020546127091e45bc59e7Kay Sievers local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
819da59577758a7a328020546127091e45bc59e7Kay Sievers local OPTS='-h --help'
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers local -A VERBS=(
819da59577758a7a328020546127091e45bc59e7Kay Sievers [ADD]='add'
819da59577758a7a328020546127091e45bc59e7Kay Sievers [REMOVE]='remove'
819da59577758a7a328020546127091e45bc59e7Kay Sievers )
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers for ((i=0; $i <= $COMP_CWORD; i++)); do
819da59577758a7a328020546127091e45bc59e7Kay Sievers if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
819da59577758a7a328020546127091e45bc59e7Kay Sievers ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
819da59577758a7a328020546127091e45bc59e7Kay Sievers verb=${COMP_WORDS[i]}
819da59577758a7a328020546127091e45bc59e7Kay Sievers break
819da59577758a7a328020546127091e45bc59e7Kay Sievers fi
819da59577758a7a328020546127091e45bc59e7Kay Sievers done
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers if [[ -z $verb && $cur = -* ]]; then
819da59577758a7a328020546127091e45bc59e7Kay Sievers COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
819da59577758a7a328020546127091e45bc59e7Kay Sievers return 0
819da59577758a7a328020546127091e45bc59e7Kay Sievers fi
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers if [[ -z $verb ]]; then
819da59577758a7a328020546127091e45bc59e7Kay Sievers comps=${VERBS[*]}
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers elif __contains_word "$verb" ${VERBS[ADD]}; then
819da59577758a7a328020546127091e45bc59e7Kay Sievers if [[ $prev = "$verb" ]]; then
819da59577758a7a328020546127091e45bc59e7Kay Sievers comps=$(cd /lib/modules; echo [0-9]*)
819da59577758a7a328020546127091e45bc59e7Kay Sievers elif [[ $prev = [0-9]* ]]; then
819da59577758a7a328020546127091e45bc59e7Kay Sievers comps=$(echo /boot/vmlinuz-$prev*)
819da59577758a7a328020546127091e45bc59e7Kay Sievers fi
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers elif __contains_word "$verb" ${VERBS[REMOVE]}; then
819da59577758a7a328020546127091e45bc59e7Kay Sievers comps=$(cd /lib/modules; echo [0-9]*)
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers fi
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
819da59577758a7a328020546127091e45bc59e7Kay Sievers return 0
819da59577758a7a328020546127091e45bc59e7Kay Sievers}
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sieverscomplete -F _kernel_install kernel-install