]>
Commit | Line | Data |
---|---|---|
9e0f94ac AZ |
1 | # shellcheck shell=bash |
2 | # run0(1) completion -*- shell-script -*- | |
3 | # SPDX-License-Identifier: LGPL-2.1-or-later | |
4 | # | |
5 | # This file is part of systemd. | |
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 <https://www.gnu.org/licenses/>. | |
19 | ||
20 | __systemctl() { | |
21 | systemctl --system --full --no-legend --no-pager --plain "$@" | |
22 | } | |
23 | ||
24 | __get_slice_units () { __systemctl list-units --all -t slice \ | |
25 | | { while read -r a b c d; do echo " $a"; done; }; } | |
26 | ||
27 | __get_machines() { | |
28 | local a b | |
29 | { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \ | |
30 | { while read a b; do echo " $a"; done; } | \ | |
31 | sort -u | |
32 | } | |
33 | ||
34 | _run0() { | |
35 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} | |
36 | local opts_with_values=( | |
37 | --machine --unit --property --description --slice -u --user -g --group --nice -D --chdir | |
38 | --setenv --background | |
39 | ) | |
40 | local OPTS="${opts_with_values[*]} -h --help -V --version --no-ask-password --slice-inherit" | |
41 | ||
42 | local i | |
43 | for (( i=1; i <= COMP_CWORD; i++ )); do | |
44 | if [[ ${COMP_WORDS[i]} != -* ]]; then | |
45 | local root_command=${COMP_WORDS[i]} | |
46 | _command_offset ${i} | |
47 | return | |
48 | fi | |
49 | ||
50 | [[ ${i} -lt ${COMP_CWORD} && " ${opts_with_values[@]} " =~ " ${COMP_WORDS[i]} " ]] && ((i++)) | |
51 | done | |
52 | ||
53 | case "${prev}" in | |
54 | --unit|--description|--nice|--setenv|--background) | |
55 | # argument required but no completions available | |
56 | return | |
57 | ;; | |
58 | --slice) | |
59 | local comps=$(__get_slice_units) | |
60 | ||
61 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
62 | return 0 | |
63 | ;; | |
64 | --property) | |
65 | local comps='CPUAccounting= MemoryAccounting= BlockIOAccounting= SendSIGHUP= | |
66 | SendSIGKILL= MemoryLimit= CPUShares= BlockIOWeight= User= Group= | |
67 | DevicePolicy= KillMode= ExitType= DeviceAllow= BlockIOReadBandwidth= | |
68 | BlockIOWriteBandwidth= BlockIODeviceWeight= Nice= Environment= | |
69 | KillSignal= RestartKillSignal= FinalKillSignal= LimitCPU= LimitFSIZE= LimitDATA= | |
70 | LimitSTACK= LimitCORE= LimitRSS= LimitNOFILE= LimitAS= LimitNPROC= | |
71 | LimitMEMLOCK= LimitLOCKS= LimitSIGPENDING= LimitMSGQUEUE= | |
72 | LimitNICE= LimitRTPRIO= LimitRTTIME= PrivateTmp= PrivateDevices= | |
73 | PrivateNetwork= NoNewPrivileges= WorkingDirectory= RootDirectory= | |
74 | TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel= | |
75 | SyslogFacility= TimerSlackNSec= OOMScoreAdjust= ReadWritePaths= | |
76 | ReadOnlyPaths= InaccessiblePaths= EnvironmentFile= | |
77 | ProtectSystem= ProtectHome= RuntimeDirectory= PassEnvironment=' | |
78 | ||
79 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
80 | return 0 | |
81 | ;; | |
82 | --machine) | |
83 | local comps=$( __get_machines ) | |
84 | ||
85 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
86 | return 0 | |
87 | ;; | |
88 | -u|--user) | |
89 | COMPREPLY=($(compgen -u -- "$cur")) | |
90 | return 0 | |
91 | ;; | |
92 | -g|--group) | |
93 | COMPREPLY=($(compgen -g -- "$cur")) | |
94 | return 0 | |
95 | ;; | |
96 | -D|--chdir) | |
97 | local comps | |
98 | if [[ -z $cur ]]; then | |
99 | comps=$(compgen -A directory -- "/" ) | |
100 | else | |
101 | comps=$(compgen -A directory -- "$cur" ) | |
102 | fi | |
103 | compopt -o filenames | |
104 | COMPREPLY=( $(compgen -W '$comps' -- "$cur" ) ) | |
105 | return 0 | |
106 | ;; | |
107 | esac | |
108 | ||
109 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
110 | return 0 | |
111 | } | |
112 | ||
113 | complete -F _run0 run0 |