Open akinomyoga opened 1 year ago
A test seems to fail in CI, though it works in my environment with Bash 5.2:
not ok 6 __bp_install_prompt_command should adjust modified PROMPT_COMMAND
# (in test file test/bash-preexec.bats, line [11](https://github.com/rcaloras/bash-preexec/actions/runs/4400455159/jobs/7705766093#step:4:12)6)
# `if (( ${#PROMPT_COMMAND[@]} == 2 )); then' failed
# /tmp/bats.2795.src: line 116: PROMPT_COMMAND: unbound variable
I guess this would be related to the version difference of Bash, but I'm not sure how to run bats
with the specified version of Bash. As far as I have looked inside the source code of bats
, the path to Bash seems to be hardcoded...
I have directly modified bats
and could reproduce the error with Bash 5.0. I have fixed the CI test.
Just to clarify, I mentioned mc
(Midnight Commander) in the original post to explain the background, but the problem is not specific to mc
. The problem happens with any commands that are added to PROMPT_COMMAND
after the shell startup.
@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 #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.