]>
Commit | Line | Data |
---|---|---|
14228c0d MB |
1 | # systemd-run(1) completion -*- shell-script -*- |
2 | # | |
3 | # This file is part of systemd. | |
4 | # | |
5 | # Copyright 2013 Zbigniew Jędrzejewski-Szmek | |
6 | # | |
7 | # systemd is free software; you can redistribute it and/or modify it | |
8 | # under the terms of the GNU Lesser General Public License as published by | |
9 | # the Free Software Foundation; either version 2.1 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # systemd is distributed in the hope that it will be useful, but | |
13 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | # General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU Lesser General Public License | |
18 | # along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ||
20 | __systemctl() { | |
21 | local mode=$1; shift 1 | |
22 | systemctl $mode --full --no-legend "$@" | |
23 | } | |
24 | ||
25 | __get_slice_units () { __systemctl $1 list-units --all -t slice \ | |
26 | | { while read -r a b c d; do echo " $a"; done; }; } | |
27 | ||
60f067b4 JS |
28 | __get_machines() { |
29 | local a b | |
30 | machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; }; | |
31 | } | |
32 | ||
14228c0d MB |
33 | _systemd_run() { |
34 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} | |
60f067b4 JS |
35 | local OPTS='-h --help --version --user --system --scope --unit --description --slice |
36 | -r --remain-after-exit --send-sighup -H --host -M --machine --service-type | |
d9dfd233 MP |
37 | --on-active --on-boot --on-startup --on-unit-active --on-unit-inactive |
38 | --on-calendar --timer-property -t --pty -q --quiet --no-block | |
39 | --uid --gid --nice --setenv -p --property --no-ask-password' | |
14228c0d MB |
40 | |
41 | local mode=--system | |
42 | local i | |
d9dfd233 MP |
43 | local opts_with_values=( |
44 | --unit --description --slice --service-type -H --host -M --machine -p --property --on-active | |
45 | --on-boot --on-startup --on-unit-active --on-unit-inactive --on-calendar --timer-property | |
46 | ) | |
14228c0d MB |
47 | for (( i=1; i <= COMP_CWORD; i++ )); do |
48 | if [[ ${COMP_WORDS[i]} != -* ]]; then | |
49 | local root_command=${COMP_WORDS[i]} | |
50 | _command_offset $i | |
51 | return | |
52 | fi | |
53 | ||
54 | [[ ${COMP_WORDS[i]} == "--user" ]] && mode=--user | |
55 | ||
d9dfd233 | 56 | [[ $i -lt $COMP_CWORD && " ${opts_with_values[@]} " =~ " ${COMP_WORDS[i]} " ]] && ((i++)) |
14228c0d MB |
57 | done |
58 | ||
59 | case "$prev" in | |
d9dfd233 | 60 | --unit|--description|--on-active|--on-boot|--on-startup|--on-unit-active|--on-unit-inactive|--on-calendar) |
14228c0d MB |
61 | # argument required but no completions available |
62 | return | |
63 | ;; | |
64 | --slice) | |
65 | local comps=$(__get_slice_units $mode) | |
66 | ||
60f067b4 JS |
67 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
68 | return 0 | |
69 | ;; | |
70 | --service-type) | |
71 | local comps='simple forking oneshot dbus notify idle' | |
72 | ||
73 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
74 | return 0 | |
75 | ;; | |
76 | -p|--property) | |
77 | local comps='CPUAccounting= MemoryAccounting= BlockIOAccounting= SendSIGHUP= | |
78 | SendSIGKILL= MemoryLimit= CPUShares= BlockIOWeight= User= Group= | |
79 | DevicePolicy= KillMode= DeviceAllow= BlockIOReadBandwidth= | |
80 | BlockIOWriteBandwidth= BlockIODeviceWeight= Nice= Environment= | |
81 | KillSignal= LimitCPU= LimitFSIZE= LimitDATA= LimitSTACK= | |
82 | LimitCORE= LimitRSS= LimitNOFILE= LimitAS= LimitNPROC= | |
83 | LimitMEMLOCK= LimitLOCKS= LimitSIGPENDING= LimitMSGQUEUE= | |
84 | LimitNICE= LimitRTPRIO= LimitRTTIME=' | |
85 | ||
86 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
87 | return 0 | |
88 | ;; | |
89 | -H|--host) | |
90 | local comps=$(compgen -A hostname) | |
91 | ||
92 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
93 | return 0 | |
94 | ;; | |
95 | -M|--machine) | |
96 | local comps=$( __get_machines ) | |
97 | ||
d9dfd233 MP |
98 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
99 | return 0 | |
100 | ;; | |
101 | --timer-property) | |
102 | local comps='AccuracySec= WakeSystem=' | |
14228c0d MB |
103 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
104 | return 0 | |
105 | ;; | |
106 | esac | |
107 | ||
108 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
109 | return 0 | |
110 | } | |
111 | ||
112 | complete -F _systemd_run systemd-run |