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