Skip to content

bash: move __ghostty_preexec_hook into __ghostty_hook - #11674

Merged
mitchellh merged 1 commit into
ghostty-org:mainfrom
jparise:bash-ps0-hook
Mar 20, 2026
Merged

mitchellh merged 1 commit into
ghostty-org:mainfrom
jparise:bash-ps0-hook

Conversation

@jparise

@jparise jparise commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

We previously used a readonly variable (__ghostty_ps0) to define the best __ghostty_preexec_hook expansion for the current bash version.

This worked pretty well, but it had the downside of managing another variable (#11258).

We can instead simplify this a bit by moving this into __ghostty_hook. I didn't take that approach originally because I wanted to avoid the bash version check on each command, but slightly loosening our guard check to just look for "__ghostty_preexec_hook" (rather than the full expansion expression) means we can bury the bash version check to the cold path.

One small gap here is that we may not update PS0 to the correct syntax if we start switching between significantly different bash versions in interactive subshells, but that seems like a pretty rare case to handle given the benefits of this approach.

We previously used a readonly variable (__ghostty_ps0) to define the
best __ghostty_preexec_hook expansion for the current bash version.

This works pretty well, but it had the downside of managing another
variable (ghostty-org#11258).

We can instead simplify this a bit by moving this into __ghostty_hook. I
didn't take that approach originally because I wanted to avoid the bash
version check on each command, but slightly loosening our guard check to
just look for "__ghostty_preexec_hook" (rather than the full expansion
expression) means we can bury the bash version check to the cold path.

One small gap here is that we may not update PS0 to the correct syntax
if we start switching between significantly different bash versions in
interactive subshells, but that seems like a pretty rare case to handle
given the benefits of this approach.
@jparise
jparise requested a review from a team as a code owner March 20, 2026 01:07
@mitchellh
mitchellh merged commit 7966740 into ghostty-org:main Mar 20, 2026
70 checks passed
@mitchellh mitchellh added this to the 1.3.2 milestone Mar 20, 2026
@jparise
jparise deleted the bash-ps0-hook branch March 20, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants