1 # systemd-run(1) completion -*- shell-script -*-
2 # SPDX-License-Identifier: LGPL-2.1+
4 # This file is part of systemd.
6 # Copyright 2013 Zbigniew Jędrzejewski-Szmek
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.
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.
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/>.
22 local mode=$1; shift 1
23 systemctl $mode --full --no-legend "$@"
26 __get_slice_units () { __systemctl $1 list-units --all -t slice \
27 | { while read -r a b c d; do echo " $a"; done; }; }
31 machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
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'
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
50 for (( i=1; i <= COMP_CWORD; i++ )); do
51 if [[ ${COMP_WORDS[i]} != -* ]]; then
52 local root_command=${COMP_WORDS[i]}
57 [[ ${COMP_WORDS[i]} == "--user" ]] && mode=--user
59 [[ $i -lt $COMP_CWORD && " ${opts_with_values[@]} " =~ " ${COMP_WORDS[i]} " ]] && ((i++))
63 --unit|--description|--on-active|--on-boot|--on-startup|--on-unit-active|--on-unit-inactive|--on-calendar)
64 # argument required but no completions available
68 local comps=$(__get_slice_units $mode)
70 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
74 local comps='simple forking oneshot dbus notify idle'
76 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
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='
94 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
98 local comps=$(compgen -A hostname)
100 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
104 local comps=$( __get_machines )
106 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
110 local comps='AccuracySec= WakeSystem='
111 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
116 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
120 complete -F _systemd_run systemd-run