8ec76163fff0a5f6aa31bb6061199829f4cfd75dThomas Hindoe Paaboel Andersen# busctl(1) completion -*- shell-script -*-
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# This file is part of systemd.
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek# Copyright 2013 Zbigniew Jędrzejewski-Szmek
8ec76163fff0a5f6aa31bb6061199829f4cfd75dThomas Hindoe Paaboel Andersen# Copyright 2014 Thomas H.P. Andersen
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# 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# 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__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
8ec76163fff0a5f6aa31bb6061199829f4cfd75dThomas Hindoe Paaboel Andersen__get_machines() {
8ec76163fff0a5f6aa31bb6061199829f4cfd75dThomas Hindoe Paaboel Andersen machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering__get_busnames() {
51e430a5b053dde2abc4bbd5d702ff2b900f10c2Kay Sievers local mode=$1
51e430a5b053dde2abc4bbd5d702ff2b900f10c2Kay Sievers busctl $mode list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering__get_objects() {
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering local busname=$2
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering busctl $mode tree --list --no-legend --no-pager $busname | { while read a b; do echo " $a"; done; };
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering__get_interfaces() {
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering local busname=$2
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering busctl $mode introspect --list --no-legend --no-pager $busname $path | { while read a b c; do [[ "$b" == "interface" ]] && echo " $a"; done; };
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering__get_members() {
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering local busname=$2
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering local interface=$4
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering busctl $mode introspect --list --no-legend --no-pager $busname $path $interface | sed -e 's/^\.//' | { while read a b c; do [[ "$b" == "$type" ]] && echo " $a"; done; };
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering__get_signature() {
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering local busname=$2
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering local interface=$4
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering local member=$5
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering busctl $mode introspect --list --no-legend --no-pager $busname $path $interface | sed -e 's/^\.//' | { while read a b c d; do [[ "$a" == "$member" ]] && echo " \"$c\""; done; };
51e430a5b053dde2abc4bbd5d702ff2b900f10c2Kay Sievers local i verb comps mode
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
17d47d8d2dee22ee4f0a7319b9603d3e33a0b28aThomas Hindoe Paaboel Andersen [STANDALONE]='-h --help --version --no-pager --no-legend --system --user
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering --show-machine --unique --acquired --activatable --list
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering --quiet --verbose --expect-reply=no --auto-start=no
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering --allow-interactive-authorization=yes --augment-creds=no'
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering [ARG]='-H --host -M --machine --address --match --timeout'
51e430a5b053dde2abc4bbd5d702ff2b900f10c2Kay Sievers if __contains_word "--user" ${COMP_WORDS[*]}; then
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek if __contains_word "$prev" ${OPTS[ARG]}; then
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek comps=$(compgen -A hostname)
8ec76163fff0a5f6aa31bb6061199829f4cfd75dThomas Hindoe Paaboel Andersen comps=$( __get_machines )
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek if [[ "$cur" = -* ]]; then
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek local -A VERBS=(
8ec76163fff0a5f6aa31bb6061199829f4cfd75dThomas Hindoe Paaboel Andersen [STANDALONE]='list help'
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering [BUSNAME]='status monitor capture tree'
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering [OBJECT]='introspect'
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering [METHOD]='call'
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering [PROPERTY_GET]='get-property'
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering [PROPERTY_SET]='set-property'
3ce09b7da2eb8b888066468663b2b5c81a05a03cZbigniew 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]}
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering n=$(($COMP_CWORD - $i))
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
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif __contains_word "$verb" ${VERBS[BUSNAME]}; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_busnames $mode)
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif __contains_word "$verb" ${VERBS[OBJECT]}; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering if [[ $n -eq 1 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_busnames $mode)
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 2 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 3 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif __contains_word "$verb" ${VERBS[METHOD]}; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering if [[ $n -eq 1 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_busnames $mode)
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 2 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 3 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 4 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_members $mode ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]} method)
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 5 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_signature $mode ${COMP_WORDS[COMP_CWORD-4]} ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif __contains_word "$verb" ${VERBS[PROPERTY_GET]}; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering if [[ $n -eq 1 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_busnames $mode)
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 2 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 3 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 4 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_members $mode ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]} property)
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif __contains_word "$verb" ${VERBS[PROPERTY_SET]}; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering if [[ $n -eq 1 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_busnames $mode)
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 2 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_objects $mode ${COMP_WORDS[COMP_CWORD-1]})
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 3 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_interfaces $mode ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 4 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_members $mode ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]} property)
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering elif [[ $n -eq 5 ]] ; then
e275f5e20457550e8fbed32e4bd5a033b248d69cLennart Poettering comps=$( __get_signature $mode ${COMP_WORDS[COMP_CWORD-4]} ${COMP_WORDS[COMP_CWORD-3]} ${COMP_WORDS[COMP_CWORD-2]} ${COMP_WORDS[COMP_CWORD-1]})
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmek COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
86cb0691b71873c6fe30a103dc98153e2d9ab507Zbigniew Jędrzejewski-Szmekcomplete -F _busctl busctl