bash: handle PROMPT_COMMAND ending in a newline (#11621)

We need to handle on more case: when an existing PROMPT_COMMAND ends in
a newline, we don't want to append a ; because that already counts as a
command separator.

We now handle all of these PROMPT_COMMAND cases:

- Ends with ; — no ; added
- Ends with \n or other whitespace — no ; added
- Ends with a command name — ; added as separator

See: #11245
pull/11643/head
Mitchell Hashimoto 2026-03-18 09:10:20 -07:00 committed by GitHub
commit 3dc69981d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 1 additions and 1 deletions

View File

@ -303,7 +303,7 @@ if (( BASH_VERSINFO[0] > 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 4) )
elif [[ $(builtin declare -p PROMPT_COMMAND 2>/dev/null) == "declare -a "* ]]; then
PROMPT_COMMAND+=(__ghostty_hook)
else
[[ "${PROMPT_COMMAND}" =~ \;[[:space:]]*$ ]] || PROMPT_COMMAND+=";"
[[ "${PROMPT_COMMAND}" =~ (\;[[:space:]]*|$'\n')$ ]] || PROMPT_COMMAND+=";"
PROMPT_COMMAND+=" __ghostty_hook"
fi
fi