]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/systemd-run
Merge pull request #31444 from bluca/semaphore
[thirdparty/systemd.git] / shell-completion / bash / systemd-run
1 # shellcheck shell=bash
2 # systemd-run(1) completion -*- shell-script -*-
3 # SPDX-License-Identifier: LGPL-2.1-or-later
4 #
5 # This file is part of systemd.
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 <https://www.gnu.org/licenses/>.
19
20 __systemctl() {
21 local mode=$1; shift 1
22 systemctl $mode --full --no-legend --no-pager --plain "$@"
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 --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
31 { while read a b; do echo " $a"; done; } | \
32 sort -u
33 }
34
35 _systemd_run() {
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
43 -h --help --version'
44
45 local mode=--system
46 local i
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
51 )
52 for (( i=1; i <= COMP_CWORD; i++ )); do
53 if [[ ${COMP_WORDS[i]} != -* ]]; then
54 local root_command=${COMP_WORDS[i]}
55 _command_offset $i
56 return
57 fi
58
59 [[ ${COMP_WORDS[i]} == "--user" ]] && mode=--user
60
61 [[ $i -lt $COMP_CWORD && " ${opts_with_values[@]} " =~ " ${COMP_WORDS[i]} " ]] && ((i++))
62 done
63
64 case "$prev" in
65 --unit|--description|--on-active|--on-boot|--on-startup|--on-unit-active|--on-unit-inactive|--on-calendar)
66 # argument required but no completions available
67 return
68 ;;
69 --slice)
70 local comps=$(__get_slice_units $mode)
71
72 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
73 return 0
74 ;;
75 --service-type)
76 local comps='simple forking oneshot dbus notify idle'
77
78 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
79 return 0
80 ;;
81 -p|--property)
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='
95
96 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
97 return 0
98 ;;
99 -H|--host)
100 local comps=$(compgen -A hostname)
101
102 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
103 return 0
104 ;;
105 -M|--machine)
106 local comps=$( __get_machines )
107
108 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
109 return 0
110 ;;
111 --timer-property)
112 local comps='AccuracySec= WakeSystem='
113 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
114 return 0
115 ;;
116 --working-directory)
117 local comps
118 if [[ -z $cur ]]; then
119 comps=$(compgen -A directory -- "/" )
120 else
121 comps=$(compgen -A directory -- "$cur" )
122 fi
123 compopt -o filenames
124 COMPREPLY=( $(compgen -W '$comps' -- "$cur" ) )
125 return 0
126 ;;
127 esac
128
129 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
130 return 0
131 }
132
133 complete -F _systemd_run systemd-run