chiark / gitweb /
sysusers: split users for remote into separate file
[elogind.git] / shell-completion / bash / busctl
index 8ce813f..49520e4 100644 (file)
@@ -1,8 +1,9 @@
-# hostnamectl(1) completion                               -*- shell-script -*-
+# busctl(1) completion                               -*- shell-script -*-
 #
 # This file is part of systemd.
 #
 # Copyright 2013 Zbigniew JÄ™drzejewski-Szmek
+# Copyright 2014 Thomas H.P. Andersen
 #
 # systemd is free software; you can redistribute it and/or modify it
 # under the terms of the GNU Lesser General Public License as published by
@@ -24,21 +25,39 @@ __contains_word () {
         done
 }
 
+__get_machines() {
+        local a b
+        machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+}
+
+__get_endpoints() {
+        local mode=$1
+        local a b
+        busctl $mode list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
+}
+
 _busctl() {
-        local i verb comps
+        local i verb comps mode
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
         local -A OPTS=(
-               [STANDALONE]='-h --help --version --no-pager --system --user
-                             --no-unique --no-machine'
-                      [ARG]='-H --host -M --machine --address
-                             --match'
+               [STANDALONE]='-h --help --version --no-pager --no-legend --system --user
+                             --show-machine --unique --acquired --activatable'
+                      [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
                 case $prev in
                         --host|-H)
                                 comps=$(compgen -A hostname)
                         ;;
+                        --machine|-M)
+                                comps=$( __get_machines )
                 esac
                 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
                 return 0
@@ -50,10 +69,11 @@ _busctl() {
         fi
 
         local -A VERBS=(
-                [STANDALONE]='list monitor'
+                [STANDALONE]='list help'
+                [ENDPOINT]='monitor status'
         )
 
-        for ((i=0; i <= COMP_CWORD; i++)); do
+        for ((i=0; i < COMP_CWORD; i++)); do
                 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
                  ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
                         verb=${COMP_WORDS[i]}
@@ -65,6 +85,8 @@ _busctl() {
                 comps=${VERBS[*]}
         elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
                 comps=''
+        elif __contains_word "$verb" ${VERBS[ENDPOINT]}; then
+                comps=$( __get_endpoints $mode)
         fi
 
         COMPREPLY=( $(compgen -W '$comps' -- "$cur") )