Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about conditional %exit_code in AUTO_NOTIFY_BODY #54

Open
1 of 4 tasks
strboul opened this issue Dec 28, 2023 · 1 comment
Open
1 of 4 tasks

Question about conditional %exit_code in AUTO_NOTIFY_BODY #54

strboul opened this issue Dec 28, 2023 · 1 comment

Comments

@strboul
Copy link

strboul commented Dec 28, 2023

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 🙌

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?

  • zplug
  • oh-my-zsh
  • Antigen
  • Other (please specify)
@CaderIdris
Copy link
Contributor

CaderIdris commented Apr 24, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants