]>
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() { | |
843cfcb1 ZJS |
20 | local mode=$1; shift 1 |
21 | systemctl $mode --full --no-legend "$@" | |
64eed40c ZJS |
22 | } |
23 | ||
24 | __get_slice_units () { __systemctl $1 list-units --all -t slice \ | |
843cfcb1 | 25 | | { while read -r a b c d; do echo " $a"; done; }; } |
64eed40c | 26 | |
761a7c71 | 27 | __get_machines() { |
843cfcb1 ZJS |
28 | local a b |
29 | machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; }; | |
761a7c71 TA |
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 | |
223f58ba YW |
39 | --no-ask-password --wait -P --pipe -G --collect --working-directory |
40 | -d --same-dir -S --shell' | |
64eed40c ZJS |
41 | |
42 | local mode=--system | |
43 | local i | |
20bde819 EV |
44 | local opts_with_values=( |
45 | --unit --description --slice --service-type -H --host -M --machine -p --property --on-active | |
46 | --on-boot --on-startup --on-unit-active --on-unit-inactive --on-calendar --timer-property | |
223f58ba | 47 | --path-property --socket-property --uid --gid --nice -E --setenv --working-directory |
20bde819 | 48 | ) |
64eed40c ZJS |
49 | for (( i=1; i <= COMP_CWORD; i++ )); do |
50 | if [[ ${COMP_WORDS[i]} != -* ]]; then | |
51 | local root_command=${COMP_WORDS[i]} | |
52 | _command_offset $i | |
53 | return | |
54 | fi | |
55 | ||
56 | [[ ${COMP_WORDS[i]} == "--user" ]] && mode=--user | |
57 | ||
20bde819 | 58 | [[ $i -lt $COMP_CWORD && " ${opts_with_values[@]} " =~ " ${COMP_WORDS[i]} " ]] && ((i++)) |
64eed40c ZJS |
59 | done |
60 | ||
61 | case "$prev" in | |
20bde819 | 62 | --unit|--description|--on-active|--on-boot|--on-startup|--on-unit-active|--on-unit-inactive|--on-calendar) |
64eed40c ZJS |
63 | # argument required but no completions available |
64 | return | |
65 | ;; | |
66 | --slice) | |
67 | local comps=$(__get_slice_units $mode) | |
68 | ||
761a7c71 TA |
69 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
70 | return 0 | |
71 | ;; | |
72 | --service-type) | |
73 | local comps='simple forking oneshot dbus notify idle' | |
74 | ||
75 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
76 | return 0 | |
77 | ;; | |
78 | -p|--property) | |
79 | local comps='CPUAccounting= MemoryAccounting= BlockIOAccounting= SendSIGHUP= | |
80 | SendSIGKILL= MemoryLimit= CPUShares= BlockIOWeight= User= Group= | |
81 | DevicePolicy= KillMode= DeviceAllow= BlockIOReadBandwidth= | |
82 | BlockIOWriteBandwidth= BlockIODeviceWeight= Nice= Environment= | |
fbb48d4c JR |
83 | KillSignal= FinalKillSignal= LimitCPU= LimitFSIZE= LimitDATA= |
84 | LimitSTACK= LimitCORE= LimitRSS= LimitNOFILE= LimitAS= LimitNPROC= | |
761a7c71 | 85 | LimitMEMLOCK= LimitLOCKS= LimitSIGPENDING= LimitMSGQUEUE= |
f961371f EV |
86 | LimitNICE= LimitRTPRIO= LimitRTTIME= PrivateTmp= PrivateDevices= |
87 | PrivateNetwork= NoNewPrivileges= WorkingDirectory= RootDirectory= | |
75d73dc9 | 88 | TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel= |
2a624c36 AP |
89 | SyslogFacility= TimerSlackNSec= OOMScoreAdjust= ReadWritePaths= |
90 | ReadOnlyPaths= InaccessiblePaths= EnvironmentFile= | |
b4c14404 | 91 | ProtectSystem= ProtectHome= RuntimeDirectory= PassEnvironment=' |
761a7c71 TA |
92 | |
93 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
94 | return 0 | |
95 | ;; | |
96 | -H|--host) | |
97 | local comps=$(compgen -A hostname) | |
98 | ||
99 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
100 | return 0 | |
101 | ;; | |
102 | -M|--machine) | |
103 | local comps=$( __get_machines ) | |
104 | ||
20bde819 EV |
105 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
106 | return 0 | |
107 | ;; | |
108 | --timer-property) | |
109 | local comps='AccuracySec= WakeSystem=' | |
64eed40c ZJS |
110 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) |
111 | return 0 | |
112 | ;; | |
223f58ba YW |
113 | --working-directory) |
114 | local comps | |
115 | if [[ -z $cur ]]; then | |
116 | comps=$(compgen -A directory -- "/" ) | |
117 | else | |
118 | comps=$(compgen -A directory -- "$cur" ) | |
119 | fi | |
120 | compopt -o filenames | |
121 | COMPREPLY=( $(compgen -W '$comps' -- "$cur" ) ) | |
122 | return 0 | |
123 | ;; | |
64eed40c ZJS |
124 | esac |
125 | ||
126 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
127 | return 0 | |
128 | } | |
129 | ||
130 | complete -F _systemd_run systemd-run |