Repository navigation
bash: move __ghostty_preexec_hook into __ghostty_hook - #11674
Merged
Merged
Conversation
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.
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.
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.