bash: detect hooks in prompt command arrays (#14266)

The delimiter-based guard treats PROMPT_COMMAND as a semicolon-separated
command list. Indexed array expansion joins elements with spaces
instead, so a hook appended after an existing element is not detected
when the integration is sourced again.

Match the full internal hook command as a substring so the guard works
for both scalar and array values. This intentionally gives up command
boundary matching; the private function name and redirection keep an
incidental match unlikely.
This commit is contained in:
Mitchell Hashimoto
2026-09-18 06:28:24 -07:00
committed by GitHub

View File

@@ -256,7 +256,7 @@ if (( BASH_VERSINFO[0] > 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 4) )
# errors from inside our hooks, but those are all terminal escape sequences
# and non-actionable.
# shellcheck disable=SC2128,SC2178,SC2179
if [[ ";${PROMPT_COMMAND[*]:-};" != *";__ghostty_hook 2>/dev/null;"* ]]; then
if [[ "${PROMPT_COMMAND[*]:-}" != *"__ghostty_hook 2>/dev/null"* ]]; then
if [[ -z "${PROMPT_COMMAND[*]}" ]]; then
if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 1) )); then
PROMPT_COMMAND=("__ghostty_hook 2>/dev/null")