Skip to content

Commit 0c8fe46

Browse files
Better handle edge-cases in $PROMPT_COMMAND (#128)
Some libraries do things like `PROMPT_COMMAND="$PROMPT_COMMAND ; _new_addition"`, that's a space-semicolon-space. It would be counter-productive to try to account for all possibilities, so just swap the install string for a no-op. Clean up no-op, it it's all that's left Co-authored-by: Ryan Caloras <[email protected]>
1 parent a44754f commit 0c8fe46

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

bash-preexec.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,16 @@ __bp_install() {
326326
local existing_prompt_command
327327
# Remove setting our trap install string and sanitize the existing prompt command string
328328
existing_prompt_command="${PROMPT_COMMAND:-}"
329-
existing_prompt_command="${existing_prompt_command//${__bp_install_string}[;$'\n']}" # Edge case of appending to PROMPT_COMMAND
330-
existing_prompt_command="${existing_prompt_command//$__bp_install_string}"
329+
# Edge case of appending to PROMPT_COMMAND
330+
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
331333
__bp_sanitize_string existing_prompt_command "$existing_prompt_command"
332334

333335
# Install our hooks in PROMPT_COMMAND to allow our trap to know when we've
334336
# actually entered something.
335337
PROMPT_COMMAND=$'__bp_precmd_invoke_cmd\n'
336-
if [[ -n "$existing_prompt_command" ]]; then
338+
if [[ "${existing_prompt_command:-:}" != ":" ]]; then
337339
PROMPT_COMMAND+=${existing_prompt_command}$'\n'
338340
fi;
339341
PROMPT_COMMAND+='__bp_interactive_mode'

0 commit comments

Comments
 (0)