summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitchell Hashimoto <m@mitchellh.com>2025-07-06 19:46:10 -0700
committerGitHub <noreply@github.com>2025-07-06 19:46:10 -0700
commitdb45fab85ee2a3038ced3e2fa3def83e22234620 (patch)
tree3d96adae65d5d83d42e5cae059ed182165cecae9
parentfbb19949343a7fdaad939c366a26b421e5c102a2 (diff)
parent65a7c81c94432a94eb5ccb8ca8d835c3f083290b (diff)
bash: conditionally add cursor shape sequences (#7839)
In #7808, we stopped using PS0 to reset the cursor shape because restoring PS0 in __ghostty_preexec was causing issues (#7802). The alternate approach of printing the cursor reset escape sequence directly from __ghostty_preexec caused a new issue: the input cursor would persist longer than intended, such as when a suspended vim process was restored to the foreground. This change takes a different approach. We now conditionally add the cursor shape escape sequences to PS0 (and PS1, for consistency) when they don't already appear. The fixes the cursor shape reset problem. The main downside to this approach is that PS0 will continue to contain this escape sequence; it won't be cleared/reset in __ghostty_preexec for the reasons described in #7808. This feels like an acceptable outcome because there's no harm in the modified PS0 existing for the life of the bash session (rather than it being modified and then restored for each command cycle), and it's consistent with how some other terminals' bash integration works (e.g. kitty).
-rw-r--r--src/shell-integration/bash/ghostty.bash4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/shell-integration/bash/ghostty.bash b/src/shell-integration/bash/ghostty.bash
index 21a6965ca..df4c7f9a7 100644
--- a/src/shell-integration/bash/ghostty.bash
+++ b/src/shell-integration/bash/ghostty.bash
@@ -122,8 +122,8 @@ function __ghostty_precmd() {
# Cursor
if [[ "$GHOSTTY_SHELL_FEATURES" == *"cursor"* ]]; then
- PS1=$PS1'\[\e[5 q\]' # blinking bar for input
- builtin printf "\e[0 q" # reset to default cursor
+ [[ "$PS1" != *'\[\e[5 q\]'* ]] && PS1=$PS1'\[\e[5 q\]' # input
+ [[ "$PS0" != *'\[\e[0 q\]'* ]] && PS0=$PS0'\[\e[0 q\]' # reset
fi
# Title (working directory)