Re-adjust PROMPT_COMMAND when PROMPT_COMMAND is modified elsewhere#143
Re-adjust PROMPT_COMMAND when PROMPT_COMMAND is modified elsewhere#143akinomyoga wants to merge 5 commits intorcaloras:masterfrom
PROMPT_COMMAND when PROMPT_COMMAND is modified elsewhere#143Conversation
|
A test seems to fail in CI, though it works in my environment with Bash 5.2: I guess this would be related to the version difference of Bash, but I'm not sure how to run Details$ head -1 /usr/bin/bats /usr/libexec/bats-core/*
==> /usr/bin/bats <==
#!/usr/bin/bash
==> /usr/libexec/bats-core/bats <==
#!/usr/bin/bash
==> /usr/libexec/bats-core/bats-exec-file <==
#!/usr/bin/bash
==> /usr/libexec/bats-core/bats-exec-suite <==
#!/usr/bin/bash
==> /usr/libexec/bats-core/bats-exec-test <==
#!/usr/bin/bash
==> /usr/libexec/bats-core/bats-format-cat <==
#!/usr/bin/bash
==> /usr/libexec/bats-core/bats-format-junit <==
#!/usr/bin/bash
==> /usr/libexec/bats-core/bats-format-pretty <==
#!/usr/bin/bash
==> /usr/libexec/bats-core/bats-format-tap <==
#!/usr/bin/bash
==> /usr/libexec/bats-core/bats-format-tap13 <==
#!/usr/bin/bash
==> /usr/libexec/bats-core/bats-preprocess <==
#!/usr/bin/bash |
8549ece to
2cee9b9
Compare
|
I have directly modified |
2cee9b9 to
9c669e6
Compare
|
Just to clarify, I mentioned @rcaloras @dimo414 Could you take a look at this PR? If you'd like separate PR for each commit, I can create separate PRs. |
1dd7680 to
c3cb27c
Compare
We try to remove the existing hooks before the re-adjustment of PROMPT_COMMAND, but it might not work when another framework saves the original value of `PROMPT_COMMAND` in another variable and tries to call it from inside their `PROMPT_COMMAND` hook. For example, Starship does that [1]. In such a case, our hooks would be called several times unexpectedly. To avoid this situation, we process our hooks only when the hooks are called at the top level. [1] https://github.com/starship/starship/blob/3d474684149e0a7959fb986f8cea1d28b4c69d87/src/init/starship.bash#L97
c3cb27c to
5171502
Compare
|
@rcaloras I'm hitting this exact issue on Bash 5.2 with direnv + atuin. When direnv modifies And of course thanks @akinomyoga for the fixes. |
- Add direnv hook initialization before bash-preexec - Fixes PROMPT_COMMAND conflicts that break atuin history - Enables direnv functionality out-of-the-box - See: rcaloras/bash-preexec#143
- Add direnv hook initialization before bash-preexec - Fixes PROMPT_COMMAND conflicts that break atuin history - Enables direnv functionality out-of-the-box - See: rcaloras/bash-preexec#143
- Add direnv hook initialization before bash-preexec - Fixes PROMPT_COMMAND conflicts that break atuin history - Enables direnv functionality out-of-the-box - See: rcaloras/bash-preexec#143
This is the fix for #140. The author of #140 seems to have fixed the issue by directly modifying the C source code of Midnight Commander
mc, but we could work around the modifiedPROMPT_COMMANDat bash-preexec's side.In this patch, when the
PROMPT_COMMANDis modified by users or by another code (such asmc) to have commands outside__bp_precmd_invoke_cmd...__bp_interactive_mode, bash-preexec adjustPROMPT_COMMANDagain so that every external command is enclosed within__bp_precmd_invoke_cmdand__bp_interactive_mode.In this PR, other code adjustments are included as in the following list. I think these commits are closely related to each other, but if you think some of them should be discussed in a separate PR, please let me know.
__bp_sanitize_stringto include some processing that has been done outside of it. (such as that of Try to better handle external modification to$PROMPT_COMMAND#128), to use the function in implementing the string manipulation ofPROMPT_COMMAND.shopt -u extglob. The problem is explained in the code comment.PROMPT_COMMAND.PROMPT_COMMAND, but it may fail when another framework saves the value of PROMPT_COMMAND in another variable. For such a case, we process our hooks only when the hooks are directly called from the top level ofPROMPT_COMMAND. The detail is explained in the commit message.