Handle bash-5.1+ PROMPT_COMMAND arrays in the bash integration#542
Merged
Conversation
systemd >= 258 ships a profile.d script that converts PROMPT_COMMAND into an array before ghostel.bash loads. The scalar capture saw only element 0 and the scalar overwrite left the other elements running at top level, where each prompt cycle they fired the DEBUG trap after the wrapper finished - unwrapping PS1 and emitting a stray 133;C after 133;A, so no row was ever marked as a prompt and prompt navigation found nothing. Capture every PROMPT_COMMAND element and collapse the variable to the wrapper alone, run the captured hooks inside the wrapper with the user command's $? restored, and guard the DEBUG trap against PROMPT_COMMAND content by matching BASH_COMMAND against ';'/newline-split fragments (nounset-safe, bash 3.2 compatible). Fixes #540
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #540.
systemd >= 258 installs
/etc/profile.d/80-systemd-osc-context.sh(enabled on Fedora 44), which convertsPROMPT_COMMANDinto a bash-5.1+ array by appending__systemd_osc_context_precmdline, and emits OSC 3008 context sequences. The OSC 3008 sequences themselves are harmless (libghostty parses them as a no-op) — the breakage was inghostel.bash:"${PROMPT_COMMAND:+$PROMPT_COMMAND}"only sees element[0]of an array, and the scalar overwrite only replaces element[0], so systemd's hook survived as a sibling array element.133;Cafter133;A. The prompt was then displayed with no semantic marks, so no row ever got theghostel-promptproperty andC-c M-p/C-c M-nfound nothing.Changes
PROMPT_COMMANDelement (scalar or array) and collapse the variable to the wrapper alone, keeping correct$?for133;Dand OSC 7 firing last (the tramp getting triggered inside local fedora-toolbox container #276 vte race).$?restored before each, so status-reporting hooks (systemd, vte) stay accurate.PROMPT_COMMANDcontent by matchingBASH_COMMANDagainst;/newline-split fragments (bash-preexec's technique), covering compound hooks appended after load. Nounset-safe and bash 3.2 compatible.Verification
PROMPT_COMMAND/ multiline PS1, bash 3.2): no behavior changes.