Bash: avoid blanking the prompt when cancelling interactive completions

This commit is contained in:
Ajeet D'Souza 2026-06-30 01:46:13 +05:30
parent e4b82c0598
commit a97f239292
2 changed files with 8 additions and 2 deletions

View File

@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- PowerShell: use fully qualified names when invoking cmdlets. - PowerShell: use fully qualified names when invoking cmdlets.
- Bash/Fish/POSIX/Zsh: resolve symlinks on Windows. - Bash/Fish/POSIX/Zsh: resolve symlinks on Windows.
- Zsh: avoid inserting a trailing space when cancelling interactive Space-Tab completions. - Zsh: avoid inserting a trailing space when cancelling interactive Space-Tab completions.
- Bash: redraw the prompt instead of blanking it when cancelling interactive Space-Tab completions.
## [0.9.9] - 2026-01-31 ## [0.9.9] - 2026-01-31

View File

@ -178,7 +178,7 @@ if [[ ${BASH_VERSINFO[0]:-0} -eq 4 && ${BASH_VERSINFO[1]:-0} -ge 4 || ${BASH_VER
# If there is a space after the last word, use interactive selection. # If there is a space after the last word, use interactive selection.
elif [[ -z ${COMP_WORDS[-1]} ]]; then elif [[ -z ${COMP_WORDS[-1]} ]]; then
# shellcheck disable=SC2312 # shellcheck disable=SC2312
__zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd)" --interactive -- "{{ "${COMP_WORDS[@]:1:${#COMP_WORDS[@]}-2}" }}")" && { if __zoxide_result="$(\command zoxide query --exclude "$(__zoxide_pwd)" --interactive -- "{{ "${COMP_WORDS[@]:1:${#COMP_WORDS[@]}-2}" }}")"; then
# In case the terminal does not respond to \e[5n or another # In case the terminal does not respond to \e[5n or another
# mechanism steals the response, it is still worth completing # mechanism steals the response, it is still worth completing
# the directory in the command line. # the directory in the command line.
@ -189,7 +189,12 @@ if [[ ${BASH_VERSINFO[0]:-0} -eq 4 && ${BASH_VERSINFO[1]:-0} -ge 4 || ${BASH_VER
# builtin "bind". # builtin "bind".
bind -x '"\e[0n": __zoxide_z_complete_helper' bind -x '"\e[0n": __zoxide_z_complete_helper'
\builtin printf '\e[5n' >/dev/tty \builtin printf '\e[5n' >/dev/tty
} else
# The interactive selection was cancelled. fzf has drawn over
# the prompt, so redraw the current line.
bind '"\e[0n": redraw-current-line'
\builtin printf '\e[5n' >/dev/tty
fi
fi fi
} }