Properly check to see if we're already installed in PROMPT_COMMAND (#185)

If there's no PROMPT_COMMAND, we will set it to be $prolog\n$epilog.
The glob $prolog\n*\n$epilog does not match that PROMPT_COMMAND since
there's only a single newline.

Co-authored-by: Koichi Murase <myoga.murase@gmail.com>
This commit is contained in:
Jeffrey Faer 2026-04-08 00:42:21 -06:00 committed by GitHub
parent 35fead9f34
commit 48b5494771
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View file

@ -510,7 +510,7 @@ __bp_install_prompt_command() {
# shellcheck disable=SC2016
local prologue='__bp_precmd_invoke_cmd "$_"'
local epilogue='__bp_interactive_mode'
if [[ "$prompt_command" == "$prologue"$'\n'*$'\n'"$epilogue" ]]; then
if [[ "$prompt_command" == "$prologue"$'\n'* && "$prompt_command" == *$'\n'"$epilogue" ]]; then
return 1
fi

View file

@ -183,6 +183,17 @@ set_exit_code_and_run_precmd() {
[ "$(join_PROMPT_COMMAND)" == "$expected_result" ]
}
@test "__bp_install_prompt_command should be skipped when already set up" {
unset -v PROMPT_COMMAND
PROMPT_COMMAND=""
# First install should succeed
__bp_install_prompt_command || return 1
# Second install should skip processing and return 1
! __bp_install_prompt_command || return 1
}
@test "__bp_sanitize_string should remove semicolons and trim space" {
__bp_sanitize_string output " true1; "$'\n'