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