From 81220d022de7232fd762051e1d0d6bba8344f49e 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. So there's a pretty good change that 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 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bash-preexec.sh b/bash-preexec.sh index 5bb11b6..075ae8e 100644 --- a/bash-preexec.sh +++ b/bash-preexec.sh @@ -328,8 +328,11 @@ __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':;/$'\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=