Skip to content

Report the submitted line in bash when the profile makes PROMPT_COMMAND an array - #1391

Merged
nedtwigg merged 2 commits into
mainfrom
fix/bash-array-prompt-command
Oct 27, 2026
Merged

nedtwigg merged 2 commits into
mainfrom
fix/bash-array-prompt-command

Conversation

@dormouse-bot

Copy link
Copy Markdown
Collaborator

On a system whose /etc/profile sources systemd's 80-systemd-osc-context.sh, such as Ubuntu 26.04, the bash integration reported every command line as __systemd_osc_context_precmdline. With this fix, E carries the submitted line again and systemd's hook still runs once per prompt.

Cause. systemd's script makes PROMPT_COMMAND an array and appends its hook. shellIntegration.bash captured "$PROMPT_COMMAND", which is element 0 only, then assigned PROMPT_COMMAND='__dormouse_633_prompt', which also replaces element 0 only. bash 5.1+ runs every element, so systemd's hook ran after __dormouse_633_prompt re-armed the DEBUG trap and was reported as the next command. The line the user actually submitted got no E/C. On bash 5.1+, the integration now folds every element into the preserved user hook and unsets the array before installing its own. Older bash runs only element 0, and its behavior is unchanged.

How this surfaced. #1390's Build & Test job ran on the ubuntu-26.04 image and failed bash: E is the whole submitted line… with bash reported ["__systemd_osc_context_precmdline"] for "true". Main's last green run used ubuntu-24.04. ci.yml runs on ubuntu-latest, so main's CI will go red the same way as runners move to 26.04.

Verification. A new test in standalone/sidecar/shell-integration.test.js gives the PTY bash a ~/.profile that builds an array PROMPT_COMMAND the way systemd does. It checks that E is the submitted line and that the profile's hook still runs once per prompt. Without the fix it fails with bash reported ["__sfx_ran"] for "true". I also ran it locally (bash 5.2.21) with systemd's real script sourced from the profile: it passes with the fix and fails without it. The existing bash and zsh integration tests still pass.

systemd's 80-systemd-osc-context.sh, sourced from /etc/profile on Ubuntu
26.04, turns PROMPT_COMMAND into an array and appends its own hook. The
bash integration captured and replaced only element 0, so on bash 5.1+
the hook ran after ours re-armed the DEBUG trap and every line reported
the hook's name as its command. Fold every element into the user's hook
and unset the array before installing ours.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: ceb602e
Status: ✅  Deploy successful!
Preview URL: https://fe96af06.mouseterm.pages.dev
Branch Preview URL: https://fix-bash-array-prompt-comman.mouseterm.pages.dev

View logs

Joining the elements into one eval'd string handed each later element the
status of the one before it, while bash 5.1+ gives every element the
command's $?. A legacy `PROMPT_COMMAND=...` assigns element 0, so systemd's
OSC 3008 hook reported every command as a success. Keep the elements as an
array and set $? before each, through a function return instead of a fork.
The test now uses systemd's own lines plus a legacy assignment, and checks
the status the appended hook sees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nedtwigg
nedtwigg merged commit 4d32685 into main Oct 27, 2026
18 of 19 checks passed
@nedtwigg
nedtwigg deleted the fix/bash-array-prompt-command branch October 27, 2026 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants