busctl revision 86cb0691b71873c6fe30a103dc98153e2d9ab507
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# hostnamectl(1) completion -*- shell-script -*-
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek#
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# This file is part of systemd.
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek#
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# Copyright 2013 Zbigniew Jędrzejewski-Szmek
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek#
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# systemd is free software; you can redistribute it and/or modify it
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# under the terms of the GNU Lesser General Public License as published by
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# the Free Software Foundation; either version 2.1 of the License, or
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# (at your option) any later version.
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek#
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# systemd is distributed in the hope that it will be useful, but
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# WITHOUT ANY WARRANTY; without even the implied warranty of
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# General Public License for more details.
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek#
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# You should have received a copy of the GNU Lesser General Public License
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# along with systemd; If not, see <http://www.gnu.org/licenses/>.
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek__contains_word () {
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek local w word=$1; shift
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek for w in "$@"; do
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek [[ $w = "$word" ]] && return
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek done
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek}
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek_busctl() {
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek local i verb comps
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek local -A OPTS=(
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek [STANDALONE]='-h --help --version --no-pager --system --user
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek --no-unique --no-machine'
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek [ARG]='-H --host -M --machine --address
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek --match'
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek )
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek if __contains_word "$prev" ${OPTS[ARG]}; then
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek case $prev in
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek --host|-H)
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek comps=$(compgen -A hostname)
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek ;;
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek esac
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek return 0
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek fi
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek if [[ "$cur" = -* ]]; then
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek return 0
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek fi
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek local -A VERBS=(
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek [STANDALONE]='list monitor'
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek )
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek for ((i=0; i <= COMP_CWORD; i++)); do
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek verb=${COMP_WORDS[i]}
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek break
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek fi
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek done
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek if [[ -z $verb ]]; then
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek comps=${VERBS[*]}
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek comps=''
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek fi
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek return 0
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek}
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmekcomplete -F _busctl busctl