-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Re-adjust PROMPT_COMMAND
when PROMPT_COMMAND
is modified elsewhere
#143
base: master
Are you sure you want to change the base?
Conversation
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 $ 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 |
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
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. |
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_COMMAND
at bash-preexec's side.In this patch, when the
PROMPT_COMMAND
is modified by users or by another code (such asmc
) to have commands outside__bp_precmd_invoke_cmd
...__bp_interactive_mode
, bash-preexec adjustPROMPT_COMMAND
again so that every external command is enclosed within__bp_precmd_invoke_cmd
and__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_string
to 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.