From 03179360511ab5e44590af4dce1390f45040f2f7 Mon Sep 17 00:00:00 2001 From: Tommy Andersson Date: Wed, 12 Feb 2025 22:38:53 +0100 Subject: [PATCH] Add option to configure persistence in notification history Option AUTO_NOTIFY_ENABLE_TRANSIENT has been added to enable and disable persistence in notification history. --- README.rst | 13 +++++++++++++ auto-notify.plugin.zsh | 5 ++++- tests/test_auto_notify_send.zunit | 4 ++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 6318ced..0d293aa 100644 --- a/README.rst +++ b/README.rst @@ -142,6 +142,19 @@ NOTE: This configuration option currently only works for Linux. # Disable notification forwarding to SSH client export AUTO_NOTIFY_ENABLE_SSH=0 +**Notification Persistence in Notification History** + +You can configure whether notifications will persist in notification history by setting the environment +variable ``AUTO_NOTIFY_ENABLE_TRANSIENT`` to enable ("1") or disable ("0"). The default value is set to 1. +NOTE: This configuration option currently only works for Linux. + +:: + + # Enable persistent notifications + export AUTO_NOTIFY_ENABLE_TRANSIENT=0 + # Disable persistent notifications + export AUTO_NOTIFY_ENABLE_TRANSIENT=1 + **Ignored Commands** diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index be8b1bb..835fd53 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -9,6 +9,9 @@ export AUTO_NOTIFY_VERSION="0.10.2" # Enable or disable notifications for SSH sessions (0 = disabled, 1 = enabled) [[ -z "$AUTO_NOTIFY_ENABLE_SSH" ]] && export AUTO_NOTIFY_ENABLE_SSH=0 +# Enable transient notifications to prevent them from being saved in the notification history +[[ -z "$AUTO_NOTIFY_ENABLE_TRANSIENT" ]] && + export AUTO_NOTIFY_ENABLE_TRANSIENT=1 # List of commands/programs to ignore sending notifications for [[ -z "$AUTO_NOTIFY_IGNORE" ]] && @@ -55,7 +58,7 @@ function _auto_notify_message() { if [[ "$platform" == "Linux" ]]; then local urgency="normal" - local transient="--hint=int:transient:1" + local transient="--hint=int:transient:$AUTO_NOTIFY_ENABLE_TRANSIENT" local icon=${AUTO_NOTIFY_ICON_SUCCESS:-""} # Exit code 130 is returned when a process is terminated with SIGINT. # Since the user is already interacting with the program, there is no diff --git a/tests/test_auto_notify_send.zunit b/tests/test_auto_notify_send.zunit index 49e477f..78123d7 100644 --- a/tests/test_auto_notify_send.zunit +++ b/tests/test_auto_notify_send.zunit @@ -89,7 +89,7 @@ assert "$lines[1]" same_as 'Notification Title: "f bar -r" Completed' assert "$lines[2]" same_as "Notification Body: Total time: 20 seconds" assert "$lines[3]" same_as "Exit code: 0" - assert "$lines[4]" same_as "--app-name=zsh --hint=int:transient:1 --urgency=normal --expire-time=15000" + assert "$lines[4]" same_as "--app-name=zsh --hint=int:transient:0 --urgency=normal --expire-time=15000" } @test 'auto-notify-send sends notification and icon on Linux on success' { @@ -104,7 +104,7 @@ assert "$lines[1]" same_as 'Notification Title: "f bar -r" Completed' assert "$lines[2]" same_as "Notification Body: Total time: 20 seconds" assert "$lines[3]" same_as "Exit code: 0" - assert "$lines[4]" same_as "--app-name=zsh --hint=int:transient:1 --urgency=normal --expire-time=15000 --icon=/path/to/success/icon.png" + assert "$lines[4]" same_as "--app-name=zsh --hint=int:transient:0 --urgency=normal --expire-time=15000 --icon=/path/to/success/icon.png" } @test 'auto-notify-send sends notification on macOS' {