From 96a26dac909af4aa69e010cd7bc2b65735f0943a Mon Sep 17 00:00:00 2001 From: Jeffrey Faer Date: Sat, 17 Feb 2024 18:51:13 -0700 Subject: [PATCH] Handle another edge case in $PROMPT_COMMAND. In particular: bash-preexec installs itself by appending __bp_install_string to $PROMPT_COMMAND. That means that there's a pretty good change that __bp_install_string will be the last thing in $PROMPT_COMMAND when __bp_install is invoked. If that happens, the $existing_prompt_command logic in __bp_install will result in the pre-existing prompt command followed by `:` and no trailing newline. That situation is not cleaned up by the two existing special cases. Fix https://github.com/rcaloras/bash-preexec/issues/153 --- bash-preexec.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bash-preexec.sh b/bash-preexec.sh index 5bb11b6..fe8ae92 100644 --- a/bash-preexec.sh +++ b/bash-preexec.sh @@ -328,8 +328,10 @@ __bp_install() { existing_prompt_command="${PROMPT_COMMAND:-}" # Edge case of appending to PROMPT_COMMAND existing_prompt_command="${existing_prompt_command//$__bp_install_string/:}" # no-op - existing_prompt_command="${existing_prompt_command//$'\n':$'\n'/$'\n'}" # remove known-token only - existing_prompt_command="${existing_prompt_command//$'\n':;/$'\n'}" # remove known-token only + # Remove some known no-op patterns. + existing_prompt_command="${existing_prompt_command//$'\n':$'\n'/$'\n'}" + existing_prompt_command="${existing_prompt_command//$'\n':;/$'\n'}" + existing_prompt_command="${existing_prompt_command%$'\n':}" __bp_sanitize_string existing_prompt_command "$existing_prompt_command" if [[ "${existing_prompt_command:-:}" == ":" ]]; then existing_prompt_command=