Skip to content

Commit 96a26da

Browse files
committed
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 #153
1 parent 1f77dc0 commit 96a26da

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

bash-preexec.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,10 @@ __bp_install() {
328328
existing_prompt_command="${PROMPT_COMMAND:-}"
329329
# Edge case of appending to PROMPT_COMMAND
330330
existing_prompt_command="${existing_prompt_command//$__bp_install_string/:}" # no-op
331-
existing_prompt_command="${existing_prompt_command//$'\n':$'\n'/$'\n'}" # remove known-token only
332-
existing_prompt_command="${existing_prompt_command//$'\n':;/$'\n'}" # remove known-token only
331+
# Remove some known no-op patterns.
332+
existing_prompt_command="${existing_prompt_command//$'\n':$'\n'/$'\n'}"
333+
existing_prompt_command="${existing_prompt_command//$'\n':;/$'\n'}"
334+
existing_prompt_command="${existing_prompt_command%$'\n':}"
333335
__bp_sanitize_string existing_prompt_command "$existing_prompt_command"
334336
if [[ "${existing_prompt_command:-:}" == ":" ]]; then
335337
existing_prompt_command=

0 commit comments

Comments
 (0)