Return original value from __bp_precmd_invoke_cmd#131
Return original value from __bp_precmd_invoke_cmd#131rcaloras merged 2 commits intorcaloras:masterfrom
__bp_precmd_invoke_cmd#131Conversation
WIthout this change, `__bp_precmd_invoke_cmd` may not restore `$?` to its original value after being run. Since `__bp_precmd_invoke_cmd` get installed as the first thing in `PROMPT_COMMAND`, this will cause problems if there is an existing `PROMPT_COMMAND` (which is perhaps not aware of `bash-preexec`) that wants to do something with the exit status of the command that was just run.
|
Found while using iTerm2's shell integration, filed an issue over there as well: https://gitlab.com/gnachman/iterm2/-/issues/10334 |
|
Ah I see this breaks one of the precmd tests. Is there a good way to only restore the value of $? if it's inside a prompt command? |
|
@jordemort thanks for opening and submitting the PR! Doing some small manual tests and I'm able to recreate. I think your fix may be good, it's just the test expects a zero return code from that function and this changes it to be the prior Could you update bash-preexec/test/bash-preexec.bats Line 178 in fd2ffa8 |
|
FWIW looking at another project that uses It's worth noting, that bash-preexec does preserve this for functions which use the |
|
cc @dimo414 as well for any thoughts. I think with the test update passing should be good to merge. |
…mmands in PROMPT_COMMAND
|
Change LGTM; I played around with it manually and it doesn't break anything on my end. I'm a little concerned there was some motivating reason this wasn't done earlier, but the behavior makes sense to me. |
Thanks for reviewing! I feel the same. I can't recall prior motivation/reasoning though. My impression is there isn't actually a standard here and that one interpretation (the simplest) is that |
|
I'll merge and cut a version in the coming week pending no other feedback. |
|
Sorry, I started chasing another squirrel and forgot about this. I'll have another look tomorrow. |
|
Thanks for updating the tests for me! This looks good, and it sounds like it won't break other people's stuff. |
|
Now available in latest 0.5.0 release. https://github.com/rcaloras/bash-preexec/releases/tag/0.5.0 |
This fixes an issue reported by @rycee (Robert Helgesson) [1]. [1] rcaloras#121 (comment)
WIthout this change,
__bp_precmd_invoke_cmdmay not restore$?to its original value after being run.Since
__bp_precmd_invoke_cmdget installed as the first thing inPROMPT_COMMAND, this will cause problems if there is an existingPROMPT_COMMAND(which is perhaps not aware ofbash-preexec) that wants to do something with the exit status of the command that was just run.