From eb2b3ed7418ee55c0912dbd54af8c6e036eb0b18 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 3 Jun 2025 01:35:10 +0200 Subject: [PATCH] macOS: option to cancel notifications on SIGINT Follow up of: #71 --- README.rst | 1 - auto-notify.plugin.zsh | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 4d4e54e..e15a536 100644 --- a/README.rst +++ b/README.rst @@ -159,7 +159,6 @@ NOTE: This configuration option currently only works for Linux. You can configure whether notifications will be cancelled when procees is terminated with SIGINT by setting the environment variable ``AUTO_NOTIFY_CANCEL_ON_SIGINT`` to enable ("1") or disable ("0"). The default value is set to 0. -NOTE: This configuration option currently only works for Linux. :: diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index c2b540e..6ac5ba9 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -54,6 +54,12 @@ function _auto_notify_message() { local DEFAULT_TITLE="\"%command\" Completed" local DEFAULT_BODY="$(echo -e "Total time: %elapsed seconds\nExit code: %exit_code")" + # Exit code 130 indicates termination by SIGINT (Ctrl+C). + # If AUTO_NOTIFY_CANCEL_ON_SIGINT is enabled, suppress the notification. + if [[ "$exit_code" -eq 130 ]] && [[ "${AUTO_NOTIFY_CANCEL_ON_SIGINT}" -eq 1 ]]; then + return + fi + local title="${AUTO_NOTIFY_TITLE:-$DEFAULT_TITLE}" local text="${AUTO_NOTIFY_BODY:-$DEFAULT_BODY}" @@ -68,11 +74,6 @@ function _auto_notify_message() { # Handle specific exit codes if [[ "$exit_code" -eq 130 ]]; then - # Exit code 130 indicates termination by SIGINT (Ctrl+C). - # If AUTO_NOTIFY_CANCEL_ON_SIGINT is enabled, suppress the notification. - if [[ "${AUTO_NOTIFY_CANCEL_ON_SIGINT}" -eq 1 ]]; then - return - fi urgency="critical" transient="--hint=int:transient:1" icon="${AUTO_NOTIFY_ICON_FAILURE:-""}"