mirror of
https://github.com/rcaloras/bash-preexec.git
synced 2026-11-03 14:39:43 -09:00
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:
parent
35fead9f34
commit
48b5494771
2 changed files with 12 additions and 1 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
Loading…
Reference in a new issue