macOS: option to cancel notifications on SIGINT

Follow up of: #71
This commit is contained in:
Paul 2025-06-03 01:35:10 +02:00
parent cac2c193d9
commit eb2b3ed741
No known key found for this signature in database
GPG Key ID: 6A5AE3C3DF890E0F
2 changed files with 6 additions and 6 deletions

View File

@ -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.
::

View File

@ -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:-""}"