Skip to content

Commit

Permalink
Handle another edge case in $PROMPT_COMMAND.
Browse files Browse the repository at this point in the history
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 rcaloras#153
  • Loading branch information
JeffFaer committed Feb 18, 2024
1 parent 1f77dc0 commit 96a26da
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bash-preexec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 96a26da

Please sign in to comment.