From dd20ba74e3b440a220907e6fe04fd860a84ddd22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 6 Nov 2025 11:55:06 +0100 Subject: [PATCH 1/2] profile/systemd-osc-context: fix overriding of PROMPT_COMMAND In https://github.com/systemd/systemd/issues/39114 users are reporting that our script overrides PROMPT_COMMAND that they had. After looking at /etc/bashrc in Fedora, I see that it only sets PROMPT_COMMAND if [ -z "$PROMPT_COMMAND" ]. Let's adjust the script so this continues to work. Fixes https://github.com/systemd/systemd/issues/39114. (This is a bit of a stretch. 39114 was originally about SecureCRT, but that was resolved in SecureCRT. But there was a lot of dicussion about the prompt being overriden, which this commit should fix.) --- profile.d/80-systemd-osc-context.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/profile.d/80-systemd-osc-context.sh b/profile.d/80-systemd-osc-context.sh index a7392eedba..60ab9904f1 100644 --- a/profile.d/80-systemd-osc-context.sh +++ b/profile.d/80-systemd-osc-context.sh @@ -57,7 +57,11 @@ __systemd_osc_context_precmdline() { } if [[ -n "${BASH_VERSION:-}" ]] && [[ "${TERM:-}" != "dumb" ]]; then - # Whenever a new prompt is shown close the previous command, and prepare new command + # Legacy bashrc will assign PROMPT_COMMAND=, which is equivalent to assigning + # index 0 in the array. Leave an empty spot to handle this gracefully. + [ -n "$(declare -p PROMPT_COMMAND 2>/dev/null)" ] || PROMPT_COMMAND+=('') + + # Whenever a new prompt is shown, close the previous command, and prepare new command PROMPT_COMMAND+=(__systemd_osc_context_precmdline) # PS0 is shown right after a prompt completed, but before the command is executed From 705e2ef19418f14ff9b90c9645391d500d06be7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 6 Nov 2025 11:56:01 +0100 Subject: [PATCH 2/2] profile/osc-context: move and extend check for TERM=dumb Let's do the check early and skip most of the file if appropriate. Also, treat missing $TERM same as "dumb". We're almost certainly at a dump terminal in that case. --- profile.d/80-systemd-osc-context.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/profile.d/80-systemd-osc-context.sh b/profile.d/80-systemd-osc-context.sh index 60ab9904f1..c83e0d3c42 100644 --- a/profile.d/80-systemd-osc-context.sh +++ b/profile.d/80-systemd-osc-context.sh @@ -13,6 +13,10 @@ # Not bash? [ -n "${BASH_VERSION:-}" ] || return 0 +# If we're on a "dumb" terminal, do not install the prompt. +# Treat missing $TERM same as "dumb". +[ "${TERM:-dumb}" = "dumb" ] && return 0 + __systemd_osc_context_escape() { # Escape according to the OSC 3008 spec. Since this requires shelling out # to 'sed' we'll only do it where it's strictly necessary, and skip it when @@ -56,7 +60,7 @@ __systemd_osc_context_precmdline() { read -r systemd_osc_context_cmd_id /dev/null)" ] || PROMPT_COMMAND+=('')