1 # systemd-run(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
4 # This file is part of systemd.
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.
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.
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/>.
20 local mode=$1; shift 1
21 systemctl $mode --full --no-legend "$@"
24 __get_slice_units () { __systemctl $1 list-units --all -t slice \
25 | { while read -r a b c d; do echo " $a"; done; }; }
29 machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
33 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
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
36 --on-active --on-boot --on-startup --on-unit-active --on-unit-inactive
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 --working-directory
40 -d --same-dir -S --shell'
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
47 --path-property --socket-property --uid --gid --nice -E --setenv --working-directory
49 for (( i=1; i <= COMP_CWORD; i++ )); do
50 if [[ ${COMP_WORDS[i]} != -* ]]; then
51 local root_command=${COMP_WORDS[i]}
56 [[ ${COMP_WORDS[i]} == "--user" ]] && mode=--user
58 [[ $i -lt $COMP_CWORD && " ${opts_with_values[@]} " =~ " ${COMP_WORDS[i]} " ]] && ((i++))
62 --unit|--description|--on-active|--on-boot|--on-startup|--on-unit-active|--on-unit-inactive|--on-calendar)
63 # argument required but no completions available
67 local comps=$(__get_slice_units $mode)
69 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
73 local comps='simple forking oneshot dbus notify idle'
75 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
79 local comps='CPUAccounting= MemoryAccounting= BlockIOAccounting= SendSIGHUP=
80 SendSIGKILL= MemoryLimit= CPUShares= BlockIOWeight= User= Group=
81 DevicePolicy= KillMode= DeviceAllow= BlockIOReadBandwidth=
82 BlockIOWriteBandwidth= BlockIODeviceWeight= Nice= Environment=
83 KillSignal= RestartKillSignal= FinalKillSignal= LimitCPU= LimitFSIZE= LimitDATA=
84 LimitSTACK= LimitCORE= LimitRSS= LimitNOFILE= LimitAS= LimitNPROC=
85 LimitMEMLOCK= LimitLOCKS= LimitSIGPENDING= LimitMSGQUEUE=
86 LimitNICE= LimitRTPRIO= LimitRTTIME= PrivateTmp= PrivateDevices=
87 PrivateNetwork= NoNewPrivileges= WorkingDirectory= RootDirectory=
88 TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel=
89 SyslogFacility= TimerSlackNSec= OOMScoreAdjust= ReadWritePaths=
90 ReadOnlyPaths= InaccessiblePaths= EnvironmentFile=
91 ProtectSystem= ProtectHome= RuntimeDirectory= PassEnvironment='
93 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
97 local comps=$(compgen -A hostname)
99 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
103 local comps=$( __get_machines )
105 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
109 local comps='AccuracySec= WakeSystem='
110 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
115 if [[ -z $cur ]]; then
116 comps=$(compgen -A directory -- "/" )
118 comps=$(compgen -A directory -- "$cur" )
121 COMPREPLY=( $(compgen -W '$comps' -- "$cur" ) )
126 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
130 complete -F _systemd_run systemd-run