95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# bootctl(1) completion -*- shell-script -*-
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# This file is part of systemd.
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# Copyright 2014 Thomas H.P. Andersen
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# systemd is free software; you can redistribute it and/or modify it
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# under the terms of the GNU Lesser General Public License as published by
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# the Free Software Foundation; either version 2.1 of the License, or
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# (at your option) any later version.
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# systemd is distributed in the hope that it will be useful, but
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# WITHOUT ANY WARRANTY; without even the implied warranty of
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# General Public License for more details.
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# You should have received a copy of the GNU Lesser General Public License
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen# along with systemd; If not, see <http://www.gnu.org/licenses/>.
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen__contains_word () {
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen local w word=$1; shift
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen for w in "$@"; do
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen [[ $w = "$word" ]] && return
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen local i verb comps
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen [STANDALONE]='-h --help --version'
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen if [[ "$cur" = -* ]]; then
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen [STANDALONE]='status'
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen for ((i=0; i < COMP_CWORD; i++)); do
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen verb=${COMP_WORDS[i]}
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen if [[ -z $verb ]]; then
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen comps=${VERBS[*]}
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersen COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
95fe27d9307628a4a593e63794000c09ecb91b95Thomas Hindoe Paaboel Andersencomplete -F _bootctl bootctl