Closed ateijelo closed 2 weeks ago
@lewis-yeung you're more at home in these matters, what's your input?
@ateijelo Do you source bash-preexec at the end of your Bash profile? I cannot "fully" reproduce the bug. I mean, if I put the example code before the OMP eval
line, neither of the two hook works, but both of them will work if sourced after OMP.
It fails for me both when I source the bash-preexec example in /etc/bash.bashrc after OMP, and if I source it interactively at the prompt. I copied the OMP init code to a file and sourced it to try to figure out what was happening and this change:
-PROMPT_COMMAND=(_omp_hook "${PROMPT_COMMAND[@]}")
+PROMPT_COMMAND+=(_omp_hook)
fixed the issue.
I'm not sure if eval vs source could be the source of the problem. I'll look at it in more depth tonight.
@lewis-yeung I tried again on a fresh Debian VM and it behaved as you described. With this /etc/bash.bashrc
(and and empty ~/.bashrc
):
source /root/.bash-preexec.sh
preexec() { echo "just typed $1"; }
precmd() { echo "printing the prompt"; }
eval "$(oh-my-posh init bash)"
The just typed
text only shows after the first command, but not on the following commands:
If I eval OMP before pre-exec:
eval "$(oh-my-posh init bash)"
source /root/.bash-preexec.sh
preexec() { echo "just typed $1"; }
precmd() { echo "printing the prompt"; }
then everything works fine:
If I change the eval line to this:
eval "$(oh-my-posh init bash | sed '/PROMPT_COMMAND=/c\ PROMPT_COMMAND+=(_omp_hook)')"
Then it almost works perfectly regardless of whether OMP's eval was before or after prexec, except on the very first command:
Oh, and saving the output of oh-my-posh init bash
to a file and sourcing it makes no difference.
@ateijelo As the documentation of bash-preexec says:
It must be the last thing imported in your bash profile.
it's recommended to source bash-preexec at the end of the profile to avoid unexpected issues, not just this one.
@ateijelo if the above comment works, can we close this?
@lewis-yeung @JanDeDobbeleer I'm ok with closing this, since there's a workaround, but Oh-My-Posh documentation also asks to be the last thing in your profile.
In general, it's always tricky when a component asks to be the last or first to be imported. It only works until two components ask the same.
@ateijelo true, but that's due to shell limitations. There's bound to be compatibility issues when we both hijack the same.
bash-preexec has moved towards working in any order: https://github.com/rcaloras/bash-preexec/pull/110, but perhaps it's not quite working.
I think OMP would benefit from the same.
Code of Conduct
What happened?
After upgrading from v18 to v23, a bash-preexec hook I had stopped working. The issue can be reproduced by setting up a preexec function just like the one on the quick start:
and sourcing that file.
The output
just typed...
never shows.In the bash init code, changing the PROMPT_COMMAND setup like this:
seems to fix it.
Theme
What OS are you seeing the problem on?
Linux
Which shell are you using?
bash
Log output