1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-10-27 10:25:06 +03:00

bash_completion: busctl - add support for --user mode

This commit is contained in:
Kay Sievers 2014-04-03 03:00:44 +02:00
parent 085ebc1b22
commit 51e430a5b0

View File

@ -31,12 +31,13 @@ __get_machines() {
} }
__get_endpoints() { __get_endpoints() {
local mode=$1
local a b local a b
busctl list --no-legend --no-pager | { while read a b; do echo " $a"; done; }; busctl $mode list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
} }
_busctl() { _busctl() {
local i verb comps local i verb comps mode
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local -A OPTS=( local -A OPTS=(
[STANDALONE]='-h --help --version --no-pager --no-legend --system --user [STANDALONE]='-h --help --version --no-pager --no-legend --system --user
@ -44,6 +45,12 @@ _busctl() {
[ARG]='-H --host -M --machine --address --match' [ARG]='-H --host -M --machine --address --match'
) )
if __contains_word "--user" ${COMP_WORDS[*]}; then
mode=--user
else
mode=--system
fi
if __contains_word "$prev" ${OPTS[ARG]}; then if __contains_word "$prev" ${OPTS[ARG]}; then
case $prev in case $prev in
--host|-H) --host|-H)
@ -79,7 +86,7 @@ _busctl() {
elif __contains_word "$verb" ${VERBS[STANDALONE]}; then elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
comps='' comps=''
elif __contains_word "$verb" ${VERBS[ENDPOINT]}; then elif __contains_word "$verb" ${VERBS[ENDPOINT]}; then
comps=$( __get_endpoints ) comps=$( __get_endpoints $mode)
fi fi
COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) COMPREPLY=( $(compgen -W '$comps' -- "$cur") )