MichaelAquilina / zsh-auto-notify

⏰ ZSH plugin that automatically sends out a notification when a long running task has completed.
GNU General Public License v3.0
415 stars 43 forks source link

Question about conditional %exit_code in AUTO_NOTIFY_BODY #54

Open strboul opened 10 months ago

strboul commented 10 months ago

Issue Details

I try to customize the notification body in order to display different emojis based on exit (status) codes. The code I put below always returns the failure one even though the status code is zero. I thought there's a trivial issue with the bash/zsh interpolation but I couldn't resolve it, so I'm wondering if someone has any idea or solution.

Thanks a lot for this nice plugin :raised_hands:

export AUTO_NOTIFY_BODY="took %elapsed seconds, status code is %exit_code $([[ %exit_code == '0' ]] && echo '✅' || echo '❌')"

Operating System (uname -a)

Linux personal 6.6.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 21 Dec 2023 19:01:01 +0000 x86_64 GNU/Linux

zsh version (zsh --version)

zsh 5.9 (x86_64-pc-linux-gnu)

auto-notify version (echo "$AUTO_NOTIFY_VERSION")

0.8.1

How is auto-notify installed?

CaderIdris commented 6 months ago

I believe the issue is that the %exit_code keyword is replaced by the exit code in the _auto_notify_format() function. It's not recognised by zsh directly.

When you're exporting the AUTO_NOTIFY_BODY environmental variable, it's evaluating %exit_code as the string "%exit_code", not the value %exit_code represents later. [[ %exit_code == '0' ]] will always evaluate as false because of this.

Dynamically changing the message based on exit code isn't currently possible. I've made a pull request that adds an icon you can customise to the notification depending on whether it completes or fails, which would result in similar behaviour to the one you're attempting.