From 0a659af55ff214c781347def6f41d7aaed63b84a Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Mon, 9 Mar 2026 09:16:29 -0400 Subject: [PATCH] bash: handle existing ; in PROMPT_COMMAND If an existing PROMPT_COMMAND was a string ending in ; (and maybe some spaces), we'd add a redundant ;, resulting in a syntax error. Now we strip any trailing `;[[:space:]]*` characters from the original string before add ours. --- src/shell-integration/bash/ghostty.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/shell-integration/bash/ghostty.bash b/src/shell-integration/bash/ghostty.bash index 49d8de4504c..6199b74207d 100644 --- a/src/shell-integration/bash/ghostty.bash +++ b/src/shell-integration/bash/ghostty.bash @@ -285,19 +285,19 @@ if (( BASH_VERSINFO[0] > 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 4) ) } # Append our hook to PROMPT_COMMAND, preserving its existing type. + # shellcheck disable=SC2128,SC2178,SC2179 if [[ ";${PROMPT_COMMAND[*]:-};" != *";__ghostty_hook;"* ]]; then if [[ -z "${PROMPT_COMMAND[*]}" ]]; then if (( BASH_VERSINFO[0] > 5 || (BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 1) )); then PROMPT_COMMAND=(__ghostty_hook) else - # shellcheck disable=SC2178 PROMPT_COMMAND="__ghostty_hook" fi elif [[ $(builtin declare -p PROMPT_COMMAND 2>/dev/null) == "declare -a "* ]]; then PROMPT_COMMAND+=(__ghostty_hook) else - # shellcheck disable=SC2179 - PROMPT_COMMAND+="; __ghostty_hook" + [[ "${PROMPT_COMMAND}" =~ \;[[:space:]]*$ ]] || PROMPT_COMMAND+=";" + PROMPT_COMMAND+=" __ghostty_hook" fi fi else