1 # shellcheck shell=bash
2 # systemd-run(1) completion -*- shell-script -*-
3 # SPDX-License-Identifier: LGPL-2.1-or-later
5 # This file is part of systemd.
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.
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.
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/>.
21 local mode=$1; shift 1
22 systemctl $mode --full --no-legend --no-pager --plain "$@"
25 __get_slice_units () { __systemctl $1 list-units --all -t slice \
26 | { while read -r a b c d; do echo " $a"; done; }; }
30 { machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
31 { while read a b; do echo " $a"; done; } | \
36 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
37 local OPTS='--no-ask-password --scope -u --unit -p --property --description --slice --slice-inherit
38 -r --remain-after-exit --send-sighup --service-type --uid --gid --nice
39 --working-directory -d --same-dir -E --setenv -t --pty -P --pipe -S --shell -q --quiet
40 --on-active --on-boot --on-startup --on-unit-active --on-unit-inactive --on-calendar
41 --on-clock-change --on-timezone-change --path-property --socket-property
42 --timer-property --no-block --wait -G --collect --user --system -H --host -M --machine
47 local opts_with_values=(
48 --unit -p --property --slice --description --service-type --uid --gid --nice --working-directory
49 -E --setenv --on-active --on-boot --on-startup --on-unit-active --on-unit-inactive --on-calendar
50 --path-property --socket-property --timer-property -H --host -M --machine
52 for (( i=1; i <= COMP_CWORD; i++ )); do
53 if [[ ${COMP_WORDS[i]} != -* ]]; then
54 local root_command=${COMP_WORDS[i]}
59 [[ ${COMP_WORDS[i]} == "--user" ]] && mode=--user
61 [[ $i -lt $COMP_CWORD && " ${opts_with_values[@]} " =~ " ${COMP_WORDS[i]} " ]] && ((i++))
65 --unit|--description|--on-active|--on-boot|--on-startup|--on-unit-active|--on-unit-inactive|--on-calendar)
66 # argument required but no completions available
70 local comps=$(__get_slice_units $mode)
72 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
76 local comps='simple forking oneshot dbus notify idle'
78 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
82 local comps='CPUAccounting= MemoryAccounting= BlockIOAccounting= SendSIGHUP=
83 SendSIGKILL= MemoryLimit= CPUShares= BlockIOWeight= User= Group=
84 DevicePolicy= KillMode= ExitType= DeviceAllow= BlockIOReadBandwidth=
85 BlockIOWriteBandwidth= BlockIODeviceWeight= Nice= Environment=
86 KillSignal= RestartKillSignal= FinalKillSignal= LimitCPU= LimitFSIZE= LimitDATA=
87 LimitSTACK= LimitCORE= LimitRSS= LimitNOFILE= LimitAS= LimitNPROC=
88 LimitMEMLOCK= LimitLOCKS= LimitSIGPENDING= LimitMSGQUEUE=
89 LimitNICE= LimitRTPRIO= LimitRTTIME= PrivateTmp= PrivateDevices=
90 PrivateNetwork= NoNewPrivileges= WorkingDirectory= RootDirectory=
91 TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel=
92 SyslogFacility= TimerSlackNSec= OOMScoreAdjust= ReadWritePaths=
93 ReadOnlyPaths= InaccessiblePaths= EnvironmentFile=
94 ProtectSystem= ProtectHome= RuntimeDirectory= PassEnvironment='
96 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
100 local comps=$(compgen -A hostname)
102 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
106 local comps=$( __get_machines )
108 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
112 local comps='AccuracySec= WakeSystem='
113 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
118 if [[ -z $cur ]]; then
119 comps=$(compgen -A directory -- "/" )
121 comps=$(compgen -A directory -- "$cur" )
124 COMPREPLY=( $(compgen -W '$comps' -- "$cur" ) )
129 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
133 complete -F _systemd_run systemd-run