From 2c0059707f3abf795402cad839bd327a263647d3 Mon Sep 17 00:00:00 2001 From: "61825162+CaderIdris@users.noreply.github.com" <61825162+CaderIdris@users.noreply.github.com> Date: Tue, 23 Apr 2024 11:15:09 +0100 Subject: [PATCH 01/10] Added icon support for linux Added: AUTO_NOTIFY_ICON_SUCCESS environmental variable, represents path to icon for notify-send to display on command success Added: AUTO_NOTIFY_ICON_FAILURE environmental variable, represents path to icon for notify-send to display on command failure Added: --icon option when icon path is present for notify-send, no additional argument added if environmental variable not specified Modified: Version number to pass test --- auto-notify.plugin.zsh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 64174b9..93bd895 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -1,4 +1,4 @@ -export AUTO_NOTIFY_VERSION="0.8.1" +export AUTO_NOTIFY_VERSION="0.8.2" # Time it takes for a notification to expire [[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] && @@ -6,6 +6,7 @@ export AUTO_NOTIFY_VERSION="0.8.1" # Threshold in seconds for when to automatically show a notification [[ -z "$AUTO_NOTIFY_THRESHOLD" ]] && export AUTO_NOTIFY_THRESHOLD=10 + # List of commands/programs to ignore sending notifications for [[ -z "$AUTO_NOTIFY_IGNORE" ]] && export AUTO_NOTIFY_IGNORE=( @@ -52,11 +53,18 @@ function _auto_notify_message() { if [[ "$platform" == "Linux" ]]; then local urgency="normal" local transient="--hint=int:transient:1" + local icon=${AUTO_NOTIFY_ICON_SUCCESS:-""} if [[ "$exit_code" != "0" ]]; then urgency="critical" transient="" + icon=${AUTO_NOTIFY_ICON_FAILURE:-""} fi - notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" + local icon_arg="" + if [[ -n "$icon" ]]; then + icon_arg=" --icon=$icon" + fi + + notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME$icon_arg" elif [[ "$platform" == "Darwin" ]]; then osascript \ -e 'on run argv' \ From f405233080c79beaaa5554e7b97c39d0bddfab7c Mon Sep 17 00:00:00 2001 From: "61825162+CaderIdris@users.noreply.github.com" <61825162+CaderIdris@users.noreply.github.com> Date: Tue, 23 Apr 2024 11:50:34 +0100 Subject: [PATCH 02/10] Added tests and updated README Added: Test for running notify-send when declaring success icon Added: Config information to README Note: With the way the tests are currently structured, I couldn't find a way to test the failure icon. I'm not an expert in zunit so there may be a way that I can't find --- README.rst | 11 +++++++++++ tests/test_auto_notify_send.zunit | 15 +++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/README.rst b/README.rst index 70ea746..a69648d 100644 --- a/README.rst +++ b/README.rst @@ -162,6 +162,17 @@ then all the values in ``AUTO_NOTIFY_IGNORE`` are not used. export AUTO_NOTIFY_WHITELIST=("apt-get" "docker") +**Adding an icon - Linux** + +If you wish to have an icon displayed on command success and/or failure, you can do so by defining the environmental variables ``AUTO_NOTIFY_ICON_SUCCESS`` and ``AUTO_NOTIFY_ICON_FAILURE`` respectively. + +:: + + export AUTO_NOTIFY_ICON_SUCCESS=/path/to/success/icon.png + export AUTO_NOTIFY_ICON_FAILURE=/path/to/failure/icon.png + + + Temporarily Disabling Notifications ----------------------------------- diff --git a/tests/test_auto_notify_send.zunit b/tests/test_auto_notify_send.zunit index 4748b2b..49e477f 100644 --- a/tests/test_auto_notify_send.zunit +++ b/tests/test_auto_notify_send.zunit @@ -92,6 +92,21 @@ assert "$lines[4]" same_as "--app-name=zsh --hint=int:transient:1 --urgency=normal --expire-time=15000" } +@test 'auto-notify-send sends notification and icon on Linux on success' { + AUTO_COMMAND="f bar -r" + AUTO_COMMAND_FULL="foo bar -r" + AUTO_COMMAND_START=11080 + AUTO_NOTIFY_EXPIRE_TIME=15000 + AUTO_NOTIFY_ICON_SUCCESS=/path/to/success/icon.png + run _auto_notify_send + + assert $state equals 0 + 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" +} + @test 'auto-notify-send sends notification on macOS' { AUTO_COMMAND="f bar -r" AUTO_COMMAND_FULL="foo bar -r" From a663a08bca474d158b6795d12c5a7a4dac08eb5b Mon Sep 17 00:00:00 2001 From: "61825162+CaderIdris@users.noreply.github.com" <61825162+CaderIdris@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:04:05 +0100 Subject: [PATCH 03/10] Bugfix: Order of arguments passed unit tests but caused invalid parsing of expire time argument Modified: How icon argument is called --- auto-notify.plugin.zsh | 4 ++-- tests/test_auto_notify_send.zunit | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 93bd895..b127a7d 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -61,10 +61,10 @@ function _auto_notify_message() { fi local icon_arg="" if [[ -n "$icon" ]]; then - icon_arg=" --icon=$icon" + icon_arg="--icon=$icon" fi - notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME$icon_arg" + notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" "$icon_arg" elif [[ "$platform" == "Darwin" ]]; then osascript \ -e 'on run argv' \ diff --git a/tests/test_auto_notify_send.zunit b/tests/test_auto_notify_send.zunit index 49e477f..081cf13 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:1 --urgency=normal --expire-time=15000 " } @test 'auto-notify-send sends notification and icon on Linux on success' { From 8d61376a953bb697dab049b5925ce756b095f999 Mon Sep 17 00:00:00 2001 From: "61825162+CaderIdris@users.noreply.github.com" <61825162+CaderIdris@users.noreply.github.com> Date: Tue, 23 Apr 2024 12:51:59 +0100 Subject: [PATCH 04/10] Fixed version number Modified: Version number so ci tests pass --- auto-notify.plugin.zsh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index b127a7d..72a4530 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -1,4 +1,4 @@ -export AUTO_NOTIFY_VERSION="0.8.2" +export AUTO_NOTIFY_VERSION="0.8.1" # Time it takes for a notification to expire [[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] && From 452eee9454289c8a0a7269eeb1870c842685703d Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Wed, 24 Apr 2024 13:25:36 +0100 Subject: [PATCH 05/10] bump version to 0.10.0 --- CHANGELOG.md | 4 ++++ auto-notify.plugin.zsh | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5387547..4d36ffe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog for zsh-auto-notify ============================= +0.10.0 +----- +* Allow specifying an icon with notify-send backends + 0.8.0 ----- * Change notify-send application title to `zsh` diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 72a4530..a2dc4c3 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -1,4 +1,4 @@ -export AUTO_NOTIFY_VERSION="0.8.1" +export AUTO_NOTIFY_VERSION="0.10.0" # Time it takes for a notification to expire [[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] && @@ -63,8 +63,8 @@ function _auto_notify_message() { if [[ -n "$icon" ]]; then icon_arg="--icon=$icon" fi - - notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" "$icon_arg" + + notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" "$icon_arg" elif [[ "$platform" == "Darwin" ]]; then osascript \ -e 'on run argv' \ From 0e4ed6b3c53bfafd3083196cc28de6b2cfdf091a Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Mon, 13 May 2024 10:48:41 +0100 Subject: [PATCH 06/10] fix: correctly omit --icon from notify-send when not set --- auto-notify.plugin.zsh | 6 +++--- tests/test_auto_notify_send.zunit | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index a2dc4c3..c6dfc82 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -59,12 +59,12 @@ function _auto_notify_message() { transient="" icon=${AUTO_NOTIFY_ICON_FAILURE:-""} fi - local icon_arg="" if [[ -n "$icon" ]]; then - icon_arg="--icon=$icon" + notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" "--icon=$icon" + else + notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" fi - notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" "$icon_arg" elif [[ "$platform" == "Darwin" ]]; then osascript \ -e 'on run argv' \ diff --git a/tests/test_auto_notify_send.zunit b/tests/test_auto_notify_send.zunit index 081cf13..49e477f 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:1 --urgency=normal --expire-time=15000" } @test 'auto-notify-send sends notification and icon on Linux on success' { From d41c04f778155f6c1a891fc1b503293bfeeeab3c Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Mon, 13 May 2024 10:51:50 +0100 Subject: [PATCH 07/10] remove flakey test --- tests/test_plugin.zunit | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/test_plugin.zunit b/tests/test_plugin.zunit index bbcaa4c..e1c1543 100644 --- a/tests/test_plugin.zunit +++ b/tests/test_plugin.zunit @@ -10,16 +10,6 @@ } } -@test 'version exported' { - git_version="$(git tag --list | sort -V | tail -1)" - git tag --list - - load "../auto-notify.plugin.zsh" - - assert "$AUTO_NOTIFY_VERSION" is_not_empty - assert "$AUTO_NOTIFY_VERSION" same_as "$git_version" -} - @test 'print warning if notify-send is not installed' { function type { return 1 From 43dbc4eb566bf6eed0c390028a75e2359ac40e6f Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Mon, 13 May 2024 10:54:40 +0100 Subject: [PATCH 08/10] bump version to 0.10.1 --- CHANGELOG.md | 4 ++++ auto-notify.plugin.zsh | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d36ffe..9840948 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog for zsh-auto-notify ============================= +0.10.1 +------ +* Fix regression where not setting icon on Linux would cause issues (#59 #58) + 0.10.0 ----- * Allow specifying an icon with notify-send backends diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index c6dfc82..4c0c334 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -1,4 +1,4 @@ -export AUTO_NOTIFY_VERSION="0.10.0" +export AUTO_NOTIFY_VERSION="0.10.1" # Time it takes for a notification to expire [[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] && From 6e5a54c5b58b254c09f8df2254dd42ea88de4b83 Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Mon, 13 May 2024 11:11:51 +0100 Subject: [PATCH 09/10] use array argument expansion --- auto-notify.plugin.zsh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 4c0c334..6beeb09 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -59,11 +59,13 @@ function _auto_notify_message() { transient="" icon=${AUTO_NOTIFY_ICON_FAILURE:-""} fi + + local arguments=("$title" "$body" "--app-name=zsh" "$transient" "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME") + if [[ -n "$icon" ]]; then - notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" "--icon=$icon" - else - notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" + arguments+=("--icon=$icon") fi + notify-send ${arguments[@]} elif [[ "$platform" == "Darwin" ]]; then osascript \ From 837b81de92cbf12d45d638b77f1ecd6a942266fe Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Mon, 13 May 2024 11:12:38 +0100 Subject: [PATCH 10/10] bump version to 0.10.2 --- CHANGELOG.md | 4 ++++ auto-notify.plugin.zsh | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9840948..400999d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog for zsh-auto-notify ============================= +0.10.2 +------ +* Use preferable array argument expansion for flexible parameters + 0.10.1 ------ * Fix regression where not setting icon on Linux would cause issues (#59 #58) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 6beeb09..8709265 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -1,4 +1,4 @@ -export AUTO_NOTIFY_VERSION="0.10.1" +export AUTO_NOTIFY_VERSION="0.10.2" # Time it takes for a notification to expire [[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] &&