I'm customizing my zsh prompt and have found the following to check if there are any background jobs:
if [[ $(jobs | wc -l) -gt 0 ]]; then # has background job(s)
number_jobs='J:${cyan}%j${no_color}'
else # no background job(s)
number_jobs=""
fi
The problem I'm facing is that the code appears to be evaluated only when I open a new session rather than after each command making this rather useless. How can I have number_jobs
re-evaluated after each command?
zsh has a special prompt sequence, like C ternary operator. The below construction means if there are one or more jobs then print their number or print nothing:
%(1j.%j.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With