agkozak / agkozak-zsh-prompt

A fast, asynchronous Zsh prompt with color ASCII indicators of Git, exit, SSH, virtual environment, and vi mode status. Framework-agnostic and customizable.
MIT License
290 stars 26 forks source link

Finished background jobs don't update prompt #37

Closed edemaine closed 2 years ago

edemaine commented 2 years ago

I was excited to try out the new background job indicator status. In most cases, it works great! However, it doesn't seem to update when the number of jobs changes dynamically without any user input, even though zsh displays the "done" message and redisplays the prompt:

user@host ~ ⟫ (sleep 5)&
[1] 25665
user@host ~ 1j ⟫                                   # no key pressed here
[1]  + 25665 done       ( sleep 5; )
user@host ~ 1j ⟫                                   # here I press ENTER
user@host ~ ⟫

On the other hand, the prompt updates fine when the count changes between commands. For example:

user@host ~ ⟫ (sleep 5000)&
[1] 25674
user@host ~ 1j ⟫ kill %1
[1]  + 25674 terminated  ( sleep 5000; )
user@host ~ ⟫

Does zsh call a callback when a job gets completed? If so, it should be easy to update the prompt then, which would make it nicer. If not, this may be impossible to fix (not a huge deal).

agkozak commented 2 years ago

@edemaine Thank you for the observation. I think we can do exactly what you describe using the TRAPCHLD function. I've uploaded changes to the develop branch of this repository; could you let me know if the prompt now works the way you want it to? I'll do a little research and make sure there won't be any unintended consequences.

agkozak commented 2 years ago

It looks to me, actually, as if the prompt expansion element %j, which I should have used instead of psvar[11], does update nicely. Rather than trying to do heroics with traps, I think I'll deprecate psvar[11] and just use %j and encourage people to use it in their custom prompts.

agkozak commented 2 years ago

OK. That should be fixed. Thanks for helping me to catch that at such an early date.

edemaine commented 2 years ago

Just confirmed that the new master branch works great! Thanks for the fix!

agkozak commented 2 years ago

No problem.