]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
shell-completion: update systemd-run
authorEisuke Kawashima <e-kwsm@users.noreply.github.com>
Thu, 10 Jul 2025 13:32:30 +0000 (22:32 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 11 Jul 2025 17:04:44 +0000 (19:04 +0200)
shell-completion/bash/systemd-run
shell-completion/zsh/_systemd-run

index 4374d519a076d6e4756f9da105f083adadfd4194..14b050ec4c66eae8bbc80f1a1c89ac8b5a213959 100644 (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
             ;;
index 6d4a3a29aec91877f094307d491d1148a93c95fa..6e284556f06d55c9c8b585661de73f78e84a3b8a 100644 (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]' \