Skip to content

Commit f4c40c7

Browse files
authored
bash: only define $__ghostty_ps0 when unset (ghostty-org#11258)
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.
2 parents 308b713 + fd557e8 commit f4c40c7

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/shell-integration/bash/ghostty.bash

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,15 @@ if (( BASH_VERSINFO[0] > 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 4) )
268268

269269
# Use function substitution in 5.3+. Otherwise, use command substitution.
270270
# Any output (including escape sequences) goes to the terminal.
271-
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 3) )); then
272-
# shellcheck disable=SC2016
273-
builtin readonly __ghostty_ps0='${ __ghostty_preexec_hook; }'
274-
else
275-
# shellcheck disable=SC2016
276-
builtin readonly __ghostty_ps0='$(__ghostty_preexec_hook >/dev/tty)'
271+
# Only define if not already set (allows re-sourcing).
272+
if [[ -z "${__ghostty_ps0+x}" ]]; then
273+
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 3) )); then
274+
# shellcheck disable=SC2016
275+
builtin readonly __ghostty_ps0='${ __ghostty_preexec_hook; }'
276+
else
277+
# shellcheck disable=SC2016
278+
builtin readonly __ghostty_ps0='$(__ghostty_preexec_hook >/dev/tty)'
279+
fi
277280
fi
278281

279282
__ghostty_hook() {

0 commit comments

Comments
 (0)