e43452d
From b7ff1f56d52becdc0820d54a26b2fbec7fbd698c Mon Sep 17 00:00:00 2001
e43452d
From: Ran Benita <ran234@gmail.com>
e43452d
Date: Wed, 2 Nov 2011 10:48:51 +0200
f1996ec
Subject: [PATCH] bash-completion: rename file since it is no longer for
f1996ec
 systemctl only (cherry picked from commit
e43452d
 f5a613c03c54cc82e92c38af0b3e1c130003a68b)
e43452d
e43452d
---
e43452d
 Makefile.am                      |    2 +-
e43452d
 src/systemctl-bash-completion.sh |  264 --------------------------------------
e43452d
 src/systemd-bash-completion.sh   |  264 ++++++++++++++++++++++++++++++++++++++
e43452d
 3 files changed, 265 insertions(+), 265 deletions(-)
e43452d
 delete mode 100644 src/systemctl-bash-completion.sh
e43452d
 create mode 100644 src/systemd-bash-completion.sh
e43452d
e43452d
diff --git a/Makefile.am b/Makefile.am
e43452d
index dabe32a..8f1ffdc 100644
e43452d
--- a/Makefile.am
e43452d
+++ b/Makefile.am
e43452d
@@ -314,7 +314,7 @@ dbusinterface_DATA += \
e43452d
 endif
e43452d
 
e43452d
 dist_bashcompletion_DATA = \
e43452d
-	src/systemctl-bash-completion.sh
e43452d
+	src/systemd-bash-completion.sh
e43452d
 
e43452d
 dist_tmpfiles_DATA = \
e43452d
 	tmpfiles.d/systemd.conf \
e43452d
diff --git a/src/systemctl-bash-completion.sh b/src/systemctl-bash-completion.sh
e43452d
deleted file mode 100644
e43452d
index 176591f..0000000
e43452d
--- a/src/systemctl-bash-completion.sh
e43452d
+++ /dev/null
e43452d
@@ -1,264 +0,0 @@
e43452d
-# This file is part of systemd.
e43452d
-#
e43452d
-# Copyright 2010 Ran Benita
e43452d
-#
e43452d
-# systemd is free software; you can redistribute it and/or modify it
e43452d
-# under the terms of the GNU General Public License as published by
e43452d
-# the Free Software Foundation; either version 2 of the License, or
e43452d
-# (at your option) any later version.
e43452d
-#
e43452d
-# systemd is distributed in the hope that it will be useful, but
e43452d
-# WITHOUT ANY WARRANTY; without even the implied warranty of
e43452d
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e43452d
-# General Public License for more details.
e43452d
-#
e43452d
-# You should have received a copy of the GNU General Public License
e43452d
-# along with systemd; If not, see <http://www.gnu.org/licenses/>.
e43452d
-
e43452d
-__systemctl() {
e43452d
-        systemctl --full --no-legend "$@"
e43452d
-}
e43452d
-
e43452d
-__contains_word () {
e43452d
-        local word=$1; shift
e43452d
-        for w in $*; do [[ $w = $word ]] && return 0; done
e43452d
-        return 1
e43452d
-}
e43452d
-
e43452d
-__filter_units_by_property () {
e43452d
-        local property=$1 value=$2 ; shift ; shift
e43452d
-        local -a units=( $* )
e43452d
-        local -a props=( $(__systemctl show --property "$property" -- ${units[*]} | grep -v ^$) )
e43452d
-        for ((i=0; $i < ${#units[*]}; i++)); do
e43452d
-                if [[ "${props[i]}" = "$property=$value" ]]; then
e43452d
-                        echo "${units[i]}"
e43452d
-                fi
e43452d
-        done
e43452d
-}
e43452d
-
e43452d
-__get_all_units      () { __systemctl list-units --all | awk '                 {print $1}' ; }
e43452d
-__get_active_units   () { __systemctl list-units       | awk '                 {print $1}' ; }
e43452d
-__get_inactive_units () { __systemctl list-units --all | awk '$3 == "inactive" {print $1}' ; }
e43452d
-__get_failed_units   () { __systemctl list-units       | awk '$3 == "failed"   {print $1}' ; }
e43452d
-__get_enabled_units  () { __systemctl list-unit-files  | awk '$2 == "enabled"  {print $1}' ; }
e43452d
-__get_disabled_units () { __systemctl list-unit-files  | awk '$2 == "disabled" {print $1}' ; }
e43452d
-__get_masked_units   () { __systemctl list-unit-files  | awk '$2 == "masked"   {print $1}' ; }
e43452d
-
e43452d
-_systemctl () {
e43452d
-        local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
e43452d
-        local verb comps
e43452d
-
e43452d
-        local -A OPTS=(
e43452d
-               [STANDALONE]='--all -a --defaults --fail --ignore-dependencies --failed --force -f --full --global
e43452d
-                             --help -h --no-ask-password --no-block --no-legend --no-pager --no-reload --no-wall
e43452d
-                             --order --require --quiet -q --privileged -P --system --user --version --runtime'
e43452d
-                      [ARG]='--host -H --kill-mode --kill-who --property -p --signal -s --type -t --root'
e43452d
-        )
e43452d
-
e43452d
-        if __contains_word "$prev" ${OPTS[ARG]}; then
e43452d
-                case $prev in
e43452d
-                        --signal|-s)
e43452d
-                                comps=$(compgen -A signal)
e43452d
-                        ;;
e43452d
-                        --type|-t)
e43452d
-                                comps='automount device mount path service snapshot socket swap target timer'
e43452d
-                        ;;
e43452d
-                        --kill-who)
e43452d
-                                comps='all control main'
e43452d
-                        ;;
e43452d
-                        --kill-mode)
e43452d
-                                comps='control-group process'
e43452d
-                        ;;
e43452d
-                        --root)
e43452d
-                                comps=$(compgen -A directory -- "$cur" )
e43452d
-                                compopt -o filenames
e43452d
-                        ;;
e43452d
-                        --host|-H)
e43452d
-                                comps=$(compgen -A hostname)
e43452d
-                        ;;
e43452d
-                        --property|-p)
e43452d
-                                comps=''
e43452d
-                        ;;
e43452d
-                esac
e43452d
-                COMPREPLY=( $(compgen -W "$comps" -- "$cur") )
e43452d
-                return 0
e43452d
-        fi
e43452d
-
e43452d
-
e43452d
-        if [[ "$cur" = -* ]]; then
e43452d
-                COMPREPLY=( $(compgen -W "${OPTS[*]}" -- "$cur") )
e43452d
-                return 0
e43452d
-        fi
e43452d
-
e43452d
-        local -A VERBS=(
e43452d
-                [ALL_UNITS]='is-active is-enabled status show mask preset'
e43452d
-            [ENABLED_UNITS]='disable reenable'
e43452d
-           [DISABLED_UNITS]='enable'
e43452d
-             [FAILED_UNITS]='reset-failed'
e43452d
-          [STARTABLE_UNITS]='start'
e43452d
-          [STOPPABLE_UNITS]='stop condstop kill try-restart condrestart'
e43452d
-         [ISOLATABLE_UNITS]='isolate'
e43452d
-         [RELOADABLE_UNITS]='reload condreload reload-or-try-restart force-reload'
e43452d
-        [RESTARTABLE_UNITS]='restart reload-or-restart'
e43452d
-             [MASKED_UNITS]='unmask'
e43452d
-                     [JOBS]='cancel'
e43452d
-                [SNAPSHOTS]='delete'
e43452d
-                     [ENVS]='set-environment unset-environment'
e43452d
-               [STANDALONE]='daemon-reexec daemon-reload default dot dump
e43452d
-                             emergency exit halt kexec list-jobs list-units
e43452d
-                             list-unit-files poweroff reboot rescue show-environment'
e43452d
-                     [NAME]='snapshot load'
e43452d
-                     [FILE]='link'
e43452d
-        )
e43452d
-
e43452d
-        for ((i=0; $i <= $COMP_CWORD; i++)); do
e43452d
-                if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
e43452d
-                 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG}]}; then
e43452d
-                        verb=${COMP_WORDS[i]}
e43452d
-                        break
e43452d
-                fi
e43452d
-        done
e43452d
-
e43452d
-        if   [[ -z $verb ]]; then
e43452d
-                comps="${VERBS[*]}"
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[ALL_UNITS]}; then
e43452d
-                comps=$( __get_all_units )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[ENABLED_UNITS]}; then
e43452d
-                comps=$( __get_enabled_units )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[DISABLED_UNITS]}; then
e43452d
-                comps=$( __get_disabled_units )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[STARTABLE_UNITS]}; then
e43452d
-                comps=$( __filter_units_by_property CanStart yes \
e43452d
-                      $( __get_inactive_units | grep -Ev '\.(device|snapshot)$' ))
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then
e43452d
-                comps=$( __filter_units_by_property CanStart yes \
e43452d
-                      $( __get_all_units | grep -Ev '\.(device|snapshot|socket|timer)$' ))
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then
e43452d
-                comps=$( __filter_units_by_property CanStop yes \
e43452d
-                      $( __get_active_units ) )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[RELOADABLE_UNITS]}; then
e43452d
-                comps=$( __filter_units_by_property CanReload yes \
e43452d
-                      $( __get_active_units ) )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[ISOLATABLE_UNITS]}; then
e43452d
-                comps=$( __filter_units_by_property AllowIsolate yes \
e43452d
-                      $( __get_all_units ) )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[FAILED_UNITS]}; then
e43452d
-                comps=$( __get_failed_units )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[MASKED_UNITS]}; then
e43452d
-                comps=$( __get_masked_units )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[NAME]}; then
e43452d
-                comps=''
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[JOBS]}; then
e43452d
-                comps=$( __systemctl list-jobs | awk '{print $1}' )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[SNAPSHOTS]}; then
e43452d
-                comps=$( __systemctl list-units --type snapshot --full --all | awk '{print $1}' )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[ENVS]}; then
e43452d
-                comps=$( __systemctl show-environment | sed 's_\([^=]\+=\).*_\1_' )
e43452d
-                compopt -o nospace
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[FILE]}; then
e43452d
-                comps=$( compgen -A file -- "$cur" )
e43452d
-                compopt -o filenames
e43452d
-        fi
e43452d
-
e43452d
-        COMPREPLY=( $(compgen -W "$comps" -- "$cur") )
e43452d
-        return 0
e43452d
-}
e43452d
-complete -F _systemctl systemctl
e43452d
-
e43452d
-__get_all_sessions () { systemd-loginctl list-sessions | awk '{print $1}' ; }
e43452d
-__get_all_users    () { systemd-loginctl list-users    | awk '{print $2}' ; }
e43452d
-__get_all_seats    () { systemd-loginctl list-seats    | awk '{print $1}' ; }
e43452d
-
e43452d
-_systemd_loginctl () {
e43452d
-        local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
e43452d
-        local verb comps
e43452d
-
e43452d
-        local -A OPTS=(
e43452d
-               [STANDALONE]='--all -a --help -h --no-pager --privileged -P --version'
e43452d
-                      [ARG]='--host -H --kill-who --property -p --signal -s'
e43452d
-        )
e43452d
-
e43452d
-        if __contains_word "$prev" ${OPTS[ARG]}; then
e43452d
-                case $prev in
e43452d
-                        --signal|-s)
e43452d
-                                comps=$(compgen -A signal)
e43452d
-                        ;;
e43452d
-                        --kill-who)
e43452d
-                                comps='all leader'
e43452d
-                        ;;
e43452d
-                        --host|-H)
e43452d
-                                comps=$(compgen -A hostname)
e43452d
-                        ;;
e43452d
-                        --property|-p)
e43452d
-                                comps=''
e43452d
-                        ;;
e43452d
-                esac
e43452d
-                COMPREPLY=( $(compgen -W "$comps" -- "$cur") )
e43452d
-                return 0
e43452d
-        fi
e43452d
-
e43452d
-
e43452d
-        if [[ "$cur" = -* ]]; then
e43452d
-                COMPREPLY=( $(compgen -W "${OPTS[*]}" -- "$cur") )
e43452d
-                return 0
e43452d
-        fi
e43452d
-
e43452d
-        local -A VERBS=(
e43452d
-                [SESSIONS]='session-status show-session activate lock-session unlock-session terminate-session kill-session'
e43452d
-                [USERS]='user-status show-user enable-linger disable-linger terminate-user kill-user'
e43452d
-                [SEATS]='seat-status show-seat terminate-seat'
e43452d
-                [STANDALONE]='list-sessions list-users list-seats flush-devices'
e43452d
-                [ATTACH]='attach'
e43452d
-        )
e43452d
-
e43452d
-        for ((i=0; $i <= $COMP_CWORD; i++)); do
e43452d
-                if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
e43452d
-                 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG}]}; then
e43452d
-                        verb=${COMP_WORDS[i]}
e43452d
-                        break
e43452d
-                fi
e43452d
-        done
e43452d
-
e43452d
-        if   [[ -z $verb ]]; then
e43452d
-                comps="${VERBS[*]}"
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[SESSIONS]}; then
e43452d
-                comps=$( __get_all_sessions )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[USERS]}; then
e43452d
-                comps=$( __get_all_users )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[SEATS]}; then
e43452d
-                comps=$( __get_all_seats )
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
e43452d
-                comps=''
e43452d
-
e43452d
-        elif __contains_word "$verb" ${VERBS[ATTACH]}; then
e43452d
-                if [[ $prev = $verb ]]; then
e43452d
-                        comps=$( __get_all_seats )
e43452d
-                else
e43452d
-                        comps=$(compgen -A file -- "$cur" )
e43452d
-                        compopt -o filenames
e43452d
-                fi
e43452d
-        fi
e43452d
-
e43452d
-        COMPREPLY=( $(compgen -W "$comps" -- "$cur") )
e43452d
-        return 0
e43452d
-}
e43452d
-complete -F _systemd_loginctl systemd-loginctl
e43452d
diff --git a/src/systemd-bash-completion.sh b/src/systemd-bash-completion.sh
e43452d
new file mode 100644
e43452d
index 0000000..176591f
e43452d
--- /dev/null
e43452d
+++ b/src/systemd-bash-completion.sh
e43452d
@@ -0,0 +1,264 @@
e43452d
+# This file is part of systemd.
e43452d
+#
e43452d
+# Copyright 2010 Ran Benita
e43452d
+#
e43452d
+# systemd is free software; you can redistribute it and/or modify it
e43452d
+# under the terms of the GNU General Public License as published by
e43452d
+# the Free Software Foundation; either version 2 of the License, or
e43452d
+# (at your option) any later version.
e43452d
+#
e43452d
+# systemd is distributed in the hope that it will be useful, but
e43452d
+# WITHOUT ANY WARRANTY; without even the implied warranty of
e43452d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e43452d
+# General Public License for more details.
e43452d
+#
e43452d
+# You should have received a copy of the GNU General Public License
e43452d
+# along with systemd; If not, see <http://www.gnu.org/licenses/>.
e43452d
+
e43452d
+__systemctl() {
e43452d
+        systemctl --full --no-legend "$@"
e43452d
+}
e43452d
+
e43452d
+__contains_word () {
e43452d
+        local word=$1; shift
e43452d
+        for w in $*; do [[ $w = $word ]] && return 0; done
e43452d
+        return 1
e43452d
+}
e43452d
+
e43452d
+__filter_units_by_property () {
e43452d
+        local property=$1 value=$2 ; shift ; shift
e43452d
+        local -a units=( $* )
e43452d
+        local -a props=( $(__systemctl show --property "$property" -- ${units[*]} | grep -v ^$) )
e43452d
+        for ((i=0; $i < ${#units[*]}; i++)); do
e43452d
+                if [[ "${props[i]}" = "$property=$value" ]]; then
e43452d
+                        echo "${units[i]}"
e43452d
+                fi
e43452d
+        done
e43452d
+}
e43452d
+
e43452d
+__get_all_units      () { __systemctl list-units --all | awk '                 {print $1}' ; }
e43452d
+__get_active_units   () { __systemctl list-units       | awk '                 {print $1}' ; }
e43452d
+__get_inactive_units () { __systemctl list-units --all | awk '$3 == "inactive" {print $1}' ; }
e43452d
+__get_failed_units   () { __systemctl list-units       | awk '$3 == "failed"   {print $1}' ; }
e43452d
+__get_enabled_units  () { __systemctl list-unit-files  | awk '$2 == "enabled"  {print $1}' ; }
e43452d
+__get_disabled_units () { __systemctl list-unit-files  | awk '$2 == "disabled" {print $1}' ; }
e43452d
+__get_masked_units   () { __systemctl list-unit-files  | awk '$2 == "masked"   {print $1}' ; }
e43452d
+
e43452d
+_systemctl () {
e43452d
+        local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
e43452d
+        local verb comps
e43452d
+
e43452d
+        local -A OPTS=(
e43452d
+               [STANDALONE]='--all -a --defaults --fail --ignore-dependencies --failed --force -f --full --global
e43452d
+                             --help -h --no-ask-password --no-block --no-legend --no-pager --no-reload --no-wall
e43452d
+                             --order --require --quiet -q --privileged -P --system --user --version --runtime'
e43452d
+                      [ARG]='--host -H --kill-mode --kill-who --property -p --signal -s --type -t --root'
e43452d
+        )
e43452d
+
e43452d
+        if __contains_word "$prev" ${OPTS[ARG]}; then
e43452d
+                case $prev in
e43452d
+                        --signal|-s)
e43452d
+                                comps=$(compgen -A signal)
e43452d
+                        ;;
e43452d
+                        --type|-t)
e43452d
+                                comps='automount device mount path service snapshot socket swap target timer'
e43452d
+                        ;;
e43452d
+                        --kill-who)
e43452d
+                                comps='all control main'
e43452d
+                        ;;
e43452d
+                        --kill-mode)
e43452d
+                                comps='control-group process'
e43452d
+                        ;;
e43452d
+                        --root)
e43452d
+                                comps=$(compgen -A directory -- "$cur" )
e43452d
+                                compopt -o filenames
e43452d
+                        ;;
e43452d
+                        --host|-H)
e43452d
+                                comps=$(compgen -A hostname)
e43452d
+                        ;;
e43452d
+                        --property|-p)
e43452d
+                                comps=''
e43452d
+                        ;;
e43452d
+                esac
e43452d
+                COMPREPLY=( $(compgen -W "$comps" -- "$cur") )
e43452d
+                return 0
e43452d
+        fi
e43452d
+
e43452d
+
e43452d
+        if [[ "$cur" = -* ]]; then
e43452d
+                COMPREPLY=( $(compgen -W "${OPTS[*]}" -- "$cur") )
e43452d
+                return 0
e43452d
+        fi
e43452d
+
e43452d
+        local -A VERBS=(
e43452d
+                [ALL_UNITS]='is-active is-enabled status show mask preset'
e43452d
+            [ENABLED_UNITS]='disable reenable'
e43452d
+           [DISABLED_UNITS]='enable'
e43452d
+             [FAILED_UNITS]='reset-failed'
e43452d
+          [STARTABLE_UNITS]='start'
e43452d
+          [STOPPABLE_UNITS]='stop condstop kill try-restart condrestart'
e43452d
+         [ISOLATABLE_UNITS]='isolate'
e43452d
+         [RELOADABLE_UNITS]='reload condreload reload-or-try-restart force-reload'
e43452d
+        [RESTARTABLE_UNITS]='restart reload-or-restart'
e43452d
+             [MASKED_UNITS]='unmask'
e43452d
+                     [JOBS]='cancel'
e43452d
+                [SNAPSHOTS]='delete'
e43452d
+                     [ENVS]='set-environment unset-environment'
e43452d
+               [STANDALONE]='daemon-reexec daemon-reload default dot dump
e43452d
+                             emergency exit halt kexec list-jobs list-units
e43452d
+                             list-unit-files poweroff reboot rescue show-environment'
e43452d
+                     [NAME]='snapshot load'
e43452d
+                     [FILE]='link'
e43452d
+        )
e43452d
+
e43452d
+        for ((i=0; $i <= $COMP_CWORD; i++)); do
e43452d
+                if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
e43452d
+                 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG}]}; then
e43452d
+                        verb=${COMP_WORDS[i]}
e43452d
+                        break
e43452d
+                fi
e43452d
+        done
e43452d
+
e43452d
+        if   [[ -z $verb ]]; then
e43452d
+                comps="${VERBS[*]}"
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[ALL_UNITS]}; then
e43452d
+                comps=$( __get_all_units )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[ENABLED_UNITS]}; then
e43452d
+                comps=$( __get_enabled_units )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[DISABLED_UNITS]}; then
e43452d
+                comps=$( __get_disabled_units )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[STARTABLE_UNITS]}; then
e43452d
+                comps=$( __filter_units_by_property CanStart yes \
e43452d
+                      $( __get_inactive_units | grep -Ev '\.(device|snapshot)$' ))
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then
e43452d
+                comps=$( __filter_units_by_property CanStart yes \
e43452d
+                      $( __get_all_units | grep -Ev '\.(device|snapshot|socket|timer)$' ))
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then
e43452d
+                comps=$( __filter_units_by_property CanStop yes \
e43452d
+                      $( __get_active_units ) )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[RELOADABLE_UNITS]}; then
e43452d
+                comps=$( __filter_units_by_property CanReload yes \
e43452d
+                      $( __get_active_units ) )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[ISOLATABLE_UNITS]}; then
e43452d
+                comps=$( __filter_units_by_property AllowIsolate yes \
e43452d
+                      $( __get_all_units ) )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[FAILED_UNITS]}; then
e43452d
+                comps=$( __get_failed_units )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[MASKED_UNITS]}; then
e43452d
+                comps=$( __get_masked_units )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[NAME]}; then
e43452d
+                comps=''
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[JOBS]}; then
e43452d
+                comps=$( __systemctl list-jobs | awk '{print $1}' )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[SNAPSHOTS]}; then
e43452d
+                comps=$( __systemctl list-units --type snapshot --full --all | awk '{print $1}' )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[ENVS]}; then
e43452d
+                comps=$( __systemctl show-environment | sed 's_\([^=]\+=\).*_\1_' )
e43452d
+                compopt -o nospace
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[FILE]}; then
e43452d
+                comps=$( compgen -A file -- "$cur" )
e43452d
+                compopt -o filenames
e43452d
+        fi
e43452d
+
e43452d
+        COMPREPLY=( $(compgen -W "$comps" -- "$cur") )
e43452d
+        return 0
e43452d
+}
e43452d
+complete -F _systemctl systemctl
e43452d
+
e43452d
+__get_all_sessions () { systemd-loginctl list-sessions | awk '{print $1}' ; }
e43452d
+__get_all_users    () { systemd-loginctl list-users    | awk '{print $2}' ; }
e43452d
+__get_all_seats    () { systemd-loginctl list-seats    | awk '{print $1}' ; }
e43452d
+
e43452d
+_systemd_loginctl () {
e43452d
+        local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
e43452d
+        local verb comps
e43452d
+
e43452d
+        local -A OPTS=(
e43452d
+               [STANDALONE]='--all -a --help -h --no-pager --privileged -P --version'
e43452d
+                      [ARG]='--host -H --kill-who --property -p --signal -s'
e43452d
+        )
e43452d
+
e43452d
+        if __contains_word "$prev" ${OPTS[ARG]}; then
e43452d
+                case $prev in
e43452d
+                        --signal|-s)
e43452d
+                                comps=$(compgen -A signal)
e43452d
+                        ;;
e43452d
+                        --kill-who)
e43452d
+                                comps='all leader'
e43452d
+                        ;;
e43452d
+                        --host|-H)
e43452d
+                                comps=$(compgen -A hostname)
e43452d
+                        ;;
e43452d
+                        --property|-p)
e43452d
+                                comps=''
e43452d
+                        ;;
e43452d
+                esac
e43452d
+                COMPREPLY=( $(compgen -W "$comps" -- "$cur") )
e43452d
+                return 0
e43452d
+        fi
e43452d
+
e43452d
+
e43452d
+        if [[ "$cur" = -* ]]; then
e43452d
+                COMPREPLY=( $(compgen -W "${OPTS[*]}" -- "$cur") )
e43452d
+                return 0
e43452d
+        fi
e43452d
+
e43452d
+        local -A VERBS=(
e43452d
+                [SESSIONS]='session-status show-session activate lock-session unlock-session terminate-session kill-session'
e43452d
+                [USERS]='user-status show-user enable-linger disable-linger terminate-user kill-user'
e43452d
+                [SEATS]='seat-status show-seat terminate-seat'
e43452d
+                [STANDALONE]='list-sessions list-users list-seats flush-devices'
e43452d
+                [ATTACH]='attach'
e43452d
+        )
e43452d
+
e43452d
+        for ((i=0; $i <= $COMP_CWORD; i++)); do
e43452d
+                if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
e43452d
+                 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG}]}; then
e43452d
+                        verb=${COMP_WORDS[i]}
e43452d
+                        break
e43452d
+                fi
e43452d
+        done
e43452d
+
e43452d
+        if   [[ -z $verb ]]; then
e43452d
+                comps="${VERBS[*]}"
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[SESSIONS]}; then
e43452d
+                comps=$( __get_all_sessions )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[USERS]}; then
e43452d
+                comps=$( __get_all_users )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[SEATS]}; then
e43452d
+                comps=$( __get_all_seats )
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
e43452d
+                comps=''
e43452d
+
e43452d
+        elif __contains_word "$verb" ${VERBS[ATTACH]}; then
e43452d
+                if [[ $prev = $verb ]]; then
e43452d
+                        comps=$( __get_all_seats )
e43452d
+                else
e43452d
+                        comps=$(compgen -A file -- "$cur" )
e43452d
+                        compopt -o filenames
e43452d
+                fi
e43452d
+        fi
e43452d
+
e43452d
+        COMPREPLY=( $(compgen -W "$comps" -- "$cur") )
e43452d
+        return 0
e43452d
+}
e43452d
+complete -F _systemd_loginctl systemd-loginctl
e43452d
-- 
e43452d
1.7.7.5
e43452d