]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
profile: skip setting PS0 when PROMPT_COMMAND= is cleared
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 9 Nov 2025 18:31:32 +0000 (03:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 9 Nov 2025 21:05:15 +0000 (06:05 +0900)
Fixes #39639.

profile.d/80-systemd-osc-context.sh

index c83e0d3c4273ebfcfecd5c1bdc73c659606b42ad..ead61b6753211e5c341999a6217650c3ab8dba0e 100644 (file)
@@ -60,6 +60,13 @@ __systemd_osc_context_precmdline() {
     read -r systemd_osc_context_cmd_id </proc/sys/kernel/random/uuid
 }
 
+__systemd_osc_context_ps0() {
+    # Skip if PROMPT_COMMAND= is cleared manually or by other profiles.
+    [ -n "${systemd_osc_context_cmd_id:-}" ] || return
+
+    printf "\033]3008;start=%s%s;type=command;cwd=%s\033\\" "$systemd_osc_context_cmd_id" "$(__systemd_osc_context_common)" "$(__systemd_osc_context_escape "$PWD")"
+}
+
 if [ -n "${BASH_VERSION:-}" ]; then
     # Legacy bashrc will assign PROMPT_COMMAND=, which is equivalent to assigning
     # index 0 in the array. Leave an empty spot to handle this gracefully.
@@ -69,5 +76,5 @@ if [ -n "${BASH_VERSION:-}" ]; then
     PROMPT_COMMAND+=(__systemd_osc_context_precmdline)
 
     # PS0 is shown right after a prompt completed, but before the command is executed
-    PS0='\033]3008;start=$systemd_osc_context_cmd_id$(__systemd_osc_context_common);type=command;cwd=$(__systemd_osc_context_escape "$PWD")\033\\'"${PS0:-}"
+    PS0='$(__systemd_osc_context_ps0)'"${PS0:-}"
 fi