~ubuntu-branches/debian/jessie/systemd/jessie

« back to all changes in this revision

Viewing changes to src/systemctl-bash-completion.sh

  • Committer: Package Import Robot
  • Author(s): Tollef Fog Heen, Tollef Fog Heen, Michael Biebl
  • Date: 2012-04-03 19:59:17 UTC
  • mfrom: (1.1.10) (6.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20120403195917-l532urrbg4pkreas
Tags: 44-1
[ Tollef Fog Heen ]
* New upstream version.
  - Backport 3492207: journal: PAGE_SIZE is not known on ppc and other
    archs
  - Backport 5a2a2a1: journal: react with immediate rotation to a couple
    of more errors
  - Backport 693ce21: util: never follow symlinks in rm_rf_children()
    Fixes CVE-2012-1174, closes: #664364
* Drop output message from init-functions hook, it's pointless.
* Only rmdir /lib/init/rw if it exists.
* Explicitly order debian-fixup before sysinit.target to prevent a
  possible race condition with the creation of sockets.  Thanks to
  Michael Biebl for debugging this.
* Always restart the initctl socket on upgrades, to mask sysvinit
  removing it.

[ Michael Biebl ]
* Remove workaround for non-interactive sessions from pam config again.
* Create compat /dev/initctl symlink in case we are upgrading from a system
  running a newer version of sysvinit (using /run/initctl) and sysvinit is
  replaced with systemd-sysv during the upgrade. Closes: #663219
* Install new man pages.
* Build-Depend on valac (>= 0.12) instead of valac-0.12. Closes: #663323

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# This file is part of systemd.
2
 
#
3
 
# Copyright 2010 Ran Benita
4
 
#
5
 
# systemd is free software; you can redistribute it and/or modify it
6
 
# under the terms of the GNU General Public License as published by
7
 
# the Free Software Foundation; either version 2 of the License, or
8
 
# (at your option) any later version.
9
 
#
10
 
# systemd is distributed in the hope that it will be useful, but
11
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
 
# General Public License for more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License
16
 
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
17
 
 
18
 
__contains_word () {
19
 
        local word=$1; shift
20
 
        for w in $*; do [[ $w = $word ]] && return 0; done
21
 
        return 1
22
 
}
23
 
 
24
 
__filter_units_by_property () {
25
 
        local property=$1 value=$2 ; shift ; shift
26
 
        local -a units=( $* )
27
 
        local -a props=( $(systemctl show --property "$property" -- ${units[*]} | grep -v ^$) )
28
 
        for ((i=0; $i < ${#units[*]}; i++)); do
29
 
                if [[ "${props[i]}" = "$property=$value" ]]; then
30
 
                        echo "${units[i]}"
31
 
                fi
32
 
        done
33
 
}
34
 
 
35
 
__get_all_units      () { systemctl list-units --full --all | awk '                 {print $1}' ; }
36
 
__get_active_units   () { systemctl list-units --full       | awk '                 {print $1}' ; }
37
 
__get_inactive_units () { systemctl list-units --full --all | awk '$3 == "inactive" {print $1}' ; }
38
 
__get_failed_units   () { systemctl list-units --full       | awk '$3 == "failed"   {print $1}' ; }
39
 
 
40
 
_systemctl () {
41
 
        local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
42
 
        local verb comps
43
 
 
44
 
        local -A OPTS=(
45
 
               [STANDALONE]='--all -a --defaults --fail --ignore-dependencies --failed --force -f --full --global
46
 
                             --help -h --no-ask-password --no-block --no-pager --no-reload --no-wall
47
 
                             --order --require --quiet -q --privileged -P --system --user --version'
48
 
                      [ARG]='--host -H --kill-mode --kill-who --property -p --signal -s --type -t'
49
 
        )
50
 
 
51
 
        if __contains_word "$prev" ${OPTS[ARG]}; then
52
 
                case $prev in
53
 
                        --signal|-s)
54
 
                                comps=$(compgen -A signal | grep '^SIG' | grep -Ev 'RTMIN|RTMAX|JUNK')
55
 
                        ;;
56
 
                        --type|-t)
57
 
                                comps='automount device mount path service snapshot socket swap target timer'
58
 
                        ;;
59
 
                        --kill-who)
60
 
                                comps='all control main'
61
 
                        ;;
62
 
                        --kill-mode)
63
 
                                comps='control-group process'
64
 
                        ;;
65
 
                        --property|-p|--host|-H)
66
 
                                comps=''
67
 
                        ;;
68
 
                esac
69
 
                COMPREPLY=( $(compgen -W "$comps" -- "$cur") )
70
 
                return 0
71
 
        fi
72
 
 
73
 
 
74
 
        if [[ "$cur" = -* ]]; then
75
 
                COMPREPLY=( $(compgen -W "${OPTS[*]}" -- "$cur") )
76
 
                return 0
77
 
        fi
78
 
 
79
 
        local -A VERBS=(
80
 
                [ALL_UNITS]='enable disable is-active is-enabled status show'
81
 
             [FAILED_UNITS]='reset-failed'
82
 
          [STARTABLE_UNITS]='start'
83
 
          [STOPPABLE_UNITS]='stop kill try-restart condrestart'
84
 
         [ISOLATABLE_UNITS]='isolate'
85
 
         [RELOADABLE_UNITS]='reload reload-or-try-restart force-reload'
86
 
          [RESTARTABLE_UNITS]='restart reload-or-restart'
87
 
                     [JOBS]='cancel'
88
 
                [SNAPSHOTS]='delete'
89
 
                     [ENVS]='set-environment unset-environment'
90
 
               [STANDALONE]='daemon-reexec daemon-reload default dot dump emergency exit halt kexec
91
 
                             list-jobs list-units poweroff reboot rescue show-environment'
92
 
                     [NAME]='snapshot load'
93
 
        )
94
 
 
95
 
        local verb
96
 
        for ((i=0; $i <= $COMP_CWORD; i++)); do
97
 
                if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
98
 
                 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG}]}; then
99
 
                        verb=${COMP_WORDS[i]}
100
 
                        break
101
 
                fi
102
 
        done
103
 
 
104
 
        if   [[ -z $verb ]]; then
105
 
                comps="${VERBS[*]}"
106
 
 
107
 
        elif __contains_word "$verb" ${VERBS[ALL_UNITS]}; then
108
 
                comps=$( __get_all_units )
109
 
 
110
 
        elif __contains_word "$verb" ${VERBS[STARTABLE_UNITS]}; then
111
 
                comps=$( __filter_units_by_property CanStart yes \
112
 
                      $( __get_inactive_units | grep -Ev '\.(device|snapshot)$' ))
113
 
 
114
 
        elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then
115
 
                comps=$( __filter_units_by_property CanStart yes \
116
 
                      $( __get_all_units | grep -Ev '\.(device|snapshot|socket|timer)$' ))
117
 
 
118
 
        elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then
119
 
                comps=$( __filter_units_by_property CanStop yes \
120
 
                      $( __get_active_units ) )
121
 
 
122
 
        elif __contains_word "$verb" ${VERBS[RELOADABLE_UNITS]}; then
123
 
                comps=$( __filter_units_by_property CanReload yes \
124
 
                      $( __get_active_units ) )
125
 
 
126
 
        elif __contains_word "$verb" ${VERBS[ISOLATABLE_UNITS]}; then
127
 
                comps=$( __filter_units_by_property AllowIsolate yes \
128
 
                      $( __get_all_units ) )
129
 
 
130
 
        elif __contains_word "$verb" ${VERBS[FAILED_UNITS]}; then
131
 
                comps=$( __get_failed_units )
132
 
 
133
 
        elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[NAME]}; then
134
 
                comps=''
135
 
 
136
 
        elif __contains_word "$verb" ${VERBS[JOBS]}; then
137
 
                comps=$( systemctl list-jobs | awk '{print $1}' )
138
 
 
139
 
        elif __contains_word "$verb" ${VERBS[SNAPSHOTS]}; then
140
 
                comps=$( systemctl list-units --type snapshot --full --all | awk '{print $1}' )
141
 
 
142
 
        elif __contains_word "$verb" ${VERBS[ENVS]}; then
143
 
                comps=$( systemctl show-environment | sed 's_\([^=]\+=\).*_\1_' )
144
 
                compopt -o nospace
145
 
        fi
146
 
 
147
 
        COMPREPLY=( $(compgen -W "$comps" -- "$cur") )
148
 
        return 0
149
 
}
150
 
complete -F _systemctl systemctl