shell-completion: update systemd-run

This commit is contained in:
Eisuke Kawashima
2025-07-10 22:32:30 +09:00
committed by Zbigniew Jędrzejewski-Szmek
parent 96ba43388f
commit 4571a1d77a
2 changed files with 69 additions and 20 deletions

View File

@@ -25,10 +25,30 @@ __systemctl() {
__get_slice_units () { __systemctl $1 list-units --all -t slice \
| { while read -r a b c d; do echo " $a"; done; }; }
__get_properties () {
systemd-analyze transient-settings scope service 2>/dev/null |
while read -r p; do [ -z "$p" ] || echo "$p="; done
}
__get_path_properties () {
systemd-analyze transient-settings path |
while read -r p; do [ -z "$p" ] || echo "$p="; done
}
__get_socket_properties () {
systemd-analyze transient-settings socket 2>/dev/null |
while read -r p; do [ -z "$p" ] || echo "$p="; done
}
__get_timer_properties () {
systemd-analyze transient-settings timer 2>/dev/null |
while read -r p; do [ -z "$p" ] || echo "$p="; done
}
__get_machines() {
local a b
{ machinectl list --full --max-addresses=0 --no-legend --no-pager 2>/dev/null; echo ".host"; } | \
{ while read a b; do echo " $a"; done; } | \
{ while read -r a b; do echo " $a"; done; } | \
sort -u
}
@@ -59,10 +79,18 @@ _systemd_run() {
done
case "$prev" in
--unit|--description|--on-active|--on-boot|--on-startup|--on-unit-active|--on-unit-inactive|--on-calendar|--background)
--unit|--description|--nice|-E|--setenv|--on-active|--on-boot|--on-startup|--on-unit-active|--on-unit-inactive|--on-calendar|--background)
# argument required but no completions available
return
;;
--uid)
_comp_compgen -- -u
return
;;
--gid)
_comp_compgen -- -g
return
;;
--expand-environment)
local comps='yes no'
@@ -82,19 +110,7 @@ _systemd_run() {
return 0
;;
-p|--property)
local comps='CPUAccounting= MemoryAccounting= BlockIOAccounting= SendSIGHUP=
SendSIGKILL= MemoryLimit= CPUShares= BlockIOWeight= User= Group=
DevicePolicy= KillMode= ExitType= DeviceAllow= BlockIOReadBandwidth=
BlockIOWriteBandwidth= BlockIODeviceWeight= Nice= Environment=
KillSignal= RestartKillSignal= FinalKillSignal= LimitCPU= LimitFSIZE= LimitDATA=
LimitSTACK= LimitCORE= LimitRSS= LimitNOFILE= LimitAS= LimitNPROC=
LimitMEMLOCK= LimitLOCKS= LimitSIGPENDING= LimitMSGQUEUE=
LimitNICE= LimitRTPRIO= LimitRTTIME= PrivateTmp= PrivateDevices=
PrivateNetwork= NoNewPrivileges= WorkingDirectory= RootDirectory=
TTYPath= SyslogIdentifier= SyslogLevelPrefix= SyslogLevel=
SyslogFacility= TimerSlackNSec= OOMScoreAdjust= ReadWritePaths=
ReadOnlyPaths= InaccessiblePaths= EnvironmentFile=
ProtectSystem= ProtectHome= RuntimeDirectory= PassEnvironment='
local comps=$(__get_properties)
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
@@ -107,12 +123,21 @@ _systemd_run() {
;;
-M|--machine)
local comps=$( __get_machines )
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
;;
--path-property)
local comps=$(__get_path_properties)
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
;;
--socket-property)
local comps=$(__get_socket_properties)
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
;;
--timer-property)
local comps='AccuracySec= WakeSystem='
local comps=$(__get_timer_properties)
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
;;

View File

@@ -37,6 +37,30 @@ __systemctl() {
_values 'NAME=VALUE' "${_properties[@]}"
}
(( $+functions[_systemd-run_path-properties] )) ||
_systemd-run_path-properties() {
local -a _properties
_properties=($( systemd-analyze transient-settings path 2>/dev/null |
while read -r p; do [ -z "$p" ] || echo "$p="; done ))
_values 'NAME=VALUE' "${_properties[@]}"
}
(( $+functions[_systemd-run_socket-properties] )) ||
_systemd-run_socket-properties() {
local -a _properties
_properties=($( systemd-analyze transient-settings socket 2>/dev/null |
while read -r p; do [ -z "$p" ] || echo "$p="; done ))
_values 'NAME=VALUE' "${_properties[@]}"
}
(( $+functions[_systemd-run_timer-properties] )) ||
_systemd-run_timer-properties() {
local -a _properties
_properties=($( systemd-analyze transient-settings timer 2>/dev/null |
while read -r p; do [ -z "$p" ] || echo "$p="; done ))
_values 'NAME=VALUE' "${_properties[@]}"
}
_arguments \
'(-G --collect --shell)'{-G,--collect}'[Unload the transient unit after it completed]' \
'--description=[Description for unit]:description' \
@@ -57,7 +81,7 @@ _arguments \
'--on-timezone-change[Defines a trigger based on system timezone changes]' \
'--on-unit-active=[Run SEC seconds after the last activation]:SEC' \
'--on-unit-inactive=[Run SEC seconds after the last deactivation]:SEC' \
'--path-property=[Set path unit property]:NAME=VALUE' \
'--path-property=[Set path unit property]:NAME=VALUE:_systemd-run_path-properties' \
'(-P --pipe)'{-P,--pipe}'[Inherit standard input, output, and error]' \
{'*-p+','*--property='}'[Set unit property]:NAME=VALUE:_systemd-run_properties' \
'(-t --pty --shell)'{-t,--pty}'[The service connects to the terminal]' \
@@ -74,9 +98,9 @@ _arguments \
'--slice=[Run in the specified slice]:slices:__systemd-run_slices' \
'--slice-inherit[Run in the inherited slice]' \
'--expand-environment=[Control expansion of environment variables]:bool:(yes no)' \
'--socket-property=[Set socket unit property]:NAME=VALUE' \
'--socket-property=[Set socket unit property]:NAME=VALUE:_systemd-run_socket-properties' \
'(--user)--system[Run as system unit]' \
'--timer-property=[Set timer unit property]:NAME=VALUE' \
'--timer-property=[Set timer unit property]:NAME=VALUE:_systemd-run_timer-properties' \
'--uid=[Run as system user]:user:_users' \
'(-u --unit)'{-u+,--unit=}'[Run under the specified unit name]:unit name' \
'(--system)--user[Run as user unit]' \