Skip to content

bash: only define $__ghostty_ps0 when unset - #11258

Merged
mitchellh merged 1 commit into
ghostty-org:mainfrom
jparise:bash-source-readonly
Mar 9, 2026
Merged

mitchellh merged 1 commit into
ghostty-org:mainfrom
jparise:bash-source-readonly

Conversation

@jparise

@jparise jparise commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

This fixes an error if the script was sourced a second time:

bash: __ghostty_ps0: readonly variable

Because this is a non-exported variable, this would only happen if the script was sourced multiple times in the same bash session.

This fixes an error if the script was sourced a second time:

    bash: __ghostty_ps0: readonly variable

Because this is a non-exported variable, this would only happen if the
script was sourced multiple times in the same bash session.
@jparise
jparise requested a review from a team as a code owner March 9, 2026 12:59
@mitchellh
mitchellh merged commit f4c40c7 into ghostty-org:main Mar 9, 2026
70 of 77 checks passed
@github-actions github-actions Bot added this to the 1.3.0 milestone Mar 9, 2026
@jparise
jparise deleted the bash-source-readonly branch March 9, 2026 13:51
jparise added a commit to jparise/ghostty that referenced this pull request Mar 20, 2026
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.
mitchellh added a commit that referenced this pull request Mar 20, 2026
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.
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