]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/systemd-run
doc,core: Read{Write,Only}Paths= and InaccessiblePaths=
[thirdparty/systemd.git] / shell-completion / bash / systemd-run
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
28 __get_machines() {
29 local a b
30 machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
31 }
32
33 _systemd_run() {
34 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
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
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'
40
41 local mode=--system
42 local i
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 )
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
56 [[ $i -lt $COMP_CWORD && " ${opts_with_values[@]} " =~ " ${COMP_WORDS[i]} " ]] && ((i++))
57 done
58
59 case "$prev" in
60 --unit|--description|--on-active|--on-boot|--on-startup|--on-unit-active|--on-unit-inactive|--on-calendar)
61 # argument required but no completions available
62 return
63 ;;
64 --slice)
65 local comps=$(__get_slice_units $mode)
66
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= PrivateTmp= PrivateDevices=
85 PrivateNetwork= NoNewPrivileges= WorkingDirectory= RootDirectory=
86 TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel=
87 SyslogFacility= TimerSlackNSec= OOMScoreAdjust= ReadWritePaths=
88 ReadOnlyPaths= InaccessiblePaths= EnvironmentFile=
89 ProtectSystem= ProtectHome= RuntimeDirectory= PassEnvironment='
90
91 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
92 return 0
93 ;;
94 -H|--host)
95 local comps=$(compgen -A hostname)
96
97 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
98 return 0
99 ;;
100 -M|--machine)
101 local comps=$( __get_machines )
102
103 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
104 return 0
105 ;;
106 --timer-property)
107 local comps='AccuracySec= WakeSystem='
108 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
109 return 0
110 ;;
111 esac
112
113 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
114 return 0
115 }
116
117 complete -F _systemd_run systemd-run