From 86849ede2a3cd77a281aa03a99b825c6eb7b4672 Mon Sep 17 00:00:00 2001 From: Jacob Birkett Date: Thu, 27 Jan 2022 18:05:20 -0700 Subject: [PATCH 01/30] Fix config being overwritten when source --- auto-notify.plugin.zsh | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 5ed5c95..3fc0ae2 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -1,13 +1,27 @@ export AUTO_NOTIFY_VERSION="0.8.0" # Time it takes for a notification to expire -export AUTO_NOTIFY_EXPIRE_TIME=8000 +[[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] && + export AUTO_NOTIFY_EXPIRE_TIME=8000 # Threshold in seconds for when to automatically show a notification -export AUTO_NOTIFY_THRESHOLD=10 +[[ -z "$AUTO_NOTIFY_THRESHOLD" ]] && + export AUTO_NOTIFY_THRESHOLD=10 # List of commands/programs to ignore sending notifications for -export AUTO_NOTIFY_IGNORE=( - "vim" "nvim" "less" "more" "man" "tig" "watch" "git commit" "top" "htop" "ssh" "nano" -) +[[ -z "$AUTO_NOTIFY_IGNORE" ]] && + export AUTO_NOTIFY_IGNORE=( + 'vim' + 'nvim' + 'less' + 'more' + 'man' + 'tig' + 'watch' + 'git commit' + 'top' + 'htop' + 'ssh' + 'nano' + ) function _auto_notify_format() { local MESSAGE="$1" From 5060c0757f2aee8fd2184671aacb56fe74d0ea4b Mon Sep 17 00:00:00 2001 From: Brendan Falk Date: Mon, 27 Jun 2022 17:12:45 -0700 Subject: [PATCH 02/30] Add Fig as an installation method to the README --- README.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.rst b/README.rst index e5dad79..2cdb3e0 100644 --- a/README.rst +++ b/README.rst @@ -64,6 +64,16 @@ Zgen_ zgen load "MichaelAquilina/zsh-auto-notify" +Fig_ + +Fig adds apps, shortcuts, and autocomplete to your existing terminal. + +Install ``zsh-auto-notify`` in just one click. + +.. image:: https://fig.io/badges/install-with-fig.svg + :target: https://fig.io/plugins/other/zsh-auto-notify_MichaelAquilina + :alt: Install with Fig + oh-my-zsh_ Copy this repository to ``$ZSH_CUSTOM/custom/plugins``, where ``$ZSH_CUSTOM`` @@ -202,6 +212,8 @@ NOTE: It is required that you use a minimum zunit version of 0.8.2 .. _ZGen: https://github.com/tarjoilija/zgen +.. _Fig: https://fig.io + .. _oh-my-zsh: https://github.com/robbyrussell/oh-my-zsh .. |GPLv3| image:: https://img.shields.io/badge/License-GPL%20v3-blue.svg From b15ae822e6459e6d96be2f48d11f8791d05e2f6c Mon Sep 17 00:00:00 2001 From: Brendan Falk Date: Tue, 28 Jun 2022 10:44:09 -0700 Subject: [PATCH 03/30] Update README.rst --- README.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 2cdb3e0..70ea746 100644 --- a/README.rst +++ b/README.rst @@ -66,9 +66,7 @@ Zgen_ Fig_ -Fig adds apps, shortcuts, and autocomplete to your existing terminal. - -Install ``zsh-auto-notify`` in just one click. +Install ``zsh-auto-notify`` with Fig in just one click. .. image:: https://fig.io/badges/install-with-fig.svg :target: https://fig.io/plugins/other/zsh-auto-notify_MichaelAquilina From 8418a6e3b243efa3ad2514ffd3144667117d5bbc Mon Sep 17 00:00:00 2001 From: Grafcube Date: Tue, 4 Apr 2023 12:38:28 +0530 Subject: [PATCH 04/30] Make notifications transient if successful --- auto-notify.plugin.zsh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 3fc0ae2..a60191d 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -51,10 +51,12 @@ function _auto_notify_message() { if [[ "$platform" == "Linux" ]]; then local urgency="normal" + local transient=--transient if [[ "$exit_code" != "0" ]]; then urgency="critical" + transient="" fi - notify-send "$title" "$body" --app-name=zsh "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" + notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" elif [[ "$platform" == "Darwin" ]]; then osascript \ -e 'on run argv' \ From 9a9f8f21bb698adbb6ebaf1831922ed805d5caec Mon Sep 17 00:00:00 2001 From: Grafcube Date: Thu, 27 Apr 2023 21:11:22 +0530 Subject: [PATCH 05/30] Quote transient --- auto-notify.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index a60191d..118af69 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -51,12 +51,12 @@ function _auto_notify_message() { if [[ "$platform" == "Linux" ]]; then local urgency="normal" - local transient=--transient + local transient="--transient" if [[ "$exit_code" != "0" ]]; then urgency="critical" transient="" fi - notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" + notify-send "$title" "$body" --app-name=zsh "$transient" "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" elif [[ "$platform" == "Darwin" ]]; then osascript \ -e 'on run argv' \ From 5a50536e59babfe62a01480070e7b3481707f9b0 Mon Sep 17 00:00:00 2001 From: Grafcube Date: Thu, 11 May 2023 17:02:14 +0530 Subject: [PATCH 06/30] Fix transient argument The transient variable must not be quoted. Otherwise the command fails with `Invalid number of options.` for unsuccessful error codes. --- 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 118af69..180a589 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -56,7 +56,7 @@ function _auto_notify_message() { urgency="critical" transient="" fi - notify-send "$title" "$body" --app-name=zsh "$transient" "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" + notify-send "$title" "$body" --app-name=zsh $transient "--urgency=$urgency" "--expire-time=$AUTO_NOTIFY_EXPIRE_TIME" elif [[ "$platform" == "Darwin" ]]; then osascript \ -e 'on run argv' \ From 00951ac085a3f27f0922fa269704ca7f976ed203 Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Thu, 11 May 2023 15:15:01 +0100 Subject: [PATCH 07/30] build: update docker job image and install libnotify-bin --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 236e963..45f4411 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ test: &test - checkout - run: name: Install Dependencies - command: apt-get update && apt-get install -y curl git ncurses-bin + command: apt-get update && apt-get install -y curl git ncurses-bin libnotify-bin - run: name: Download requirements command: | @@ -25,7 +25,7 @@ test: &test jobs: lint: docker: - - image: "python:3.7-stretch" + - image: "python:3.11" steps: - checkout - run: From 993f5de86ec607e129da8eb2b55d1524865d808f Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Thu, 11 May 2023 15:23:14 +0100 Subject: [PATCH 08/30] fix: update tests to include --transient flag --- tests/test_auto_notify_send.zunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_auto_notify_send.zunit b/tests/test_auto_notify_send.zunit index 5704f6b..b1e00cf 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 --urgency=normal --expire-time=15000" + assert "$lines[4]" same_as "--app-name=zsh --transient --urgency=normal --expire-time=15000" } @test 'auto-notify-send sends notification on macOS' { From 9b6bc124f064a19ca2b41123b38f5c624a484e31 Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Fri, 2 Jun 2023 13:55:02 +0100 Subject: [PATCH 09/30] fix: backwards compatible transient flag --- auto-notify.plugin.zsh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 180a589..b908913 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -1,4 +1,4 @@ -export AUTO_NOTIFY_VERSION="0.8.0" +export AUTO_NOTIFY_VERSION="0.8.1" # Time it takes for a notification to expire [[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] && @@ -51,7 +51,7 @@ function _auto_notify_message() { if [[ "$platform" == "Linux" ]]; then local urgency="normal" - local transient="--transient" + local transient="--hint=int:transient:1" if [[ "$exit_code" != "0" ]]; then urgency="critical" transient="" From 22b2c61ed18514b4002acc626d7f19aa7cb2e34c Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Fri, 2 Jun 2023 14:01:43 +0100 Subject: [PATCH 10/30] fix: transient test case --- tests/test_auto_notify_send.zunit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_auto_notify_send.zunit b/tests/test_auto_notify_send.zunit index b1e00cf..4748b2b 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 --transient --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 on macOS' { From f4afef6fa9749e23ae8531b36b7c5039f7bac52f Mon Sep 17 00:00:00 2001 From: Dries De Peuter Date: Wed, 27 Dec 2023 23:01:21 +0100 Subject: [PATCH 11/30] fix: mute notifications over ssh --- auto-notify.plugin.zsh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index b908913..64174b9 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -77,6 +77,12 @@ function _is_auto_notify_ignored() { # Remove leading whitespace target_command="$(echo "$target_command" | sed -e 's/^ *//')" + # If the command is being run over SSH, then ignore it + if [[ -n ${SSH_CLIENT-} || -n ${SSH_TTY-} || -n ${SSH_CONNECTION-} ]]; then + print "yes" + return + fi + # Remove sudo prefix from command if detected if [[ "$target_command" == "sudo "* ]]; then target_command="${target_command/sudo /}" 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 12/30] 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 13/30] 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 14/30] 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 15/30] 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 16/30] 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 17/30] 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 18/30] 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 19/30] 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 20/30] 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 21/30] 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" ]] && From a79a412f3abc33edb15678e823c05b26ef7243cd Mon Sep 17 00:00:00 2001 From: Grafcube Date: Sun, 16 Jun 2024 00:21:26 +0530 Subject: [PATCH 22/30] Treat code 130 as success --- 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 8709265..ce5276a 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -54,7 +54,7 @@ function _auto_notify_message() { local urgency="normal" local transient="--hint=int:transient:1" local icon=${AUTO_NOTIFY_ICON_SUCCESS:-""} - if [[ "$exit_code" != "0" ]]; then + if [[ "$exit_code" != "0" ]] && [[ "$exit_code" != "130" ]]; then urgency="critical" transient="" icon=${AUTO_NOTIFY_ICON_FAILURE:-""} From 76a527a66bf2ab5a3cdaf4b548771aae65e25df9 Mon Sep 17 00:00:00 2001 From: Grafcube Date: Mon, 8 Jul 2024 19:53:31 +0530 Subject: [PATCH 23/30] Add a comment explaining why 130 is treated as success --- auto-notify.plugin.zsh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index ce5276a..591a47e 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -54,6 +54,9 @@ function _auto_notify_message() { local urgency="normal" local transient="--hint=int:transient:1" 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 + # need to make the notification persistent. if [[ "$exit_code" != "0" ]] && [[ "$exit_code" != "130" ]]; then urgency="critical" transient="" From 63f70f3c33c290b9b1768e1208f0ad8530cf358d Mon Sep 17 00:00:00 2001 From: eeleater Date: Mon, 16 Sep 2024 20:20:39 +0200 Subject: [PATCH 24/30] auto-notify.plugin.zsh aktualisiert Changed Plugin to use ntfy instead of notify-send, to send events to phone. Signed-off-by: eeleater --- auto-notify.plugin.zsh | 43 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 591a47e..d70cf79 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -41,7 +41,7 @@ function _auto_notify_message() { local exit_code="$3" local platform="$(uname)" # Run using echo -e in order to make sure notify-send picks up new line - local DEFAULT_TITLE="\"%command\" Completed" + local DEFAULT_TITLE="ZSH: \"%command\" Completed" local DEFAULT_BODY="$(echo -e "Total time: %elapsed seconds\nExit code: %exit_code")" local title="${AUTO_NOTIFY_TITLE:-$DEFAULT_TITLE}" @@ -50,36 +50,19 @@ function _auto_notify_message() { title="$(_auto_notify_format "$title" "$command" "$elapsed" "$exit_code")" body="$(_auto_notify_format "$text" "$command" "$elapsed" "$exit_code")" - if [[ "$platform" == "Linux" ]]; then - local urgency="normal" - local transient="--hint=int:transient:1" - 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 - # need to make the notification persistent. - if [[ "$exit_code" != "0" ]] && [[ "$exit_code" != "130" ]]; then - urgency="critical" - 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 - arguments+=("--icon=$icon") - fi - notify-send ${arguments[@]} - - elif [[ "$platform" == "Darwin" ]]; then - osascript \ - -e 'on run argv' \ - -e 'display notification (item 1 of argv) with title (item 2 of argv)' \ - -e 'end run' \ - "$body" "$title" - else - printf "Unknown platform for sending notifications: $platform\n" - printf "Please post an issue on gitub.com/MichaelAquilina/zsh-auto-notify/issues/\n" + local urgency="default" + 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 + # need to make the notification persistent. + if [[ "$exit_code" != "0" ]] && [[ "$exit_code" != "130" ]]; then + urgency="high" + icon=${AUTO_NOTIFY_ICON_FAILURE:-""} fi + + local arguments=("--title=$title" "--priority=$urgency" "$body") + + ntfy publish zsh_events ${arguments[@]} } function _is_auto_notify_ignored() { From 8a328a37bdd6b0dda9bb2c176e63304133b50d35 Mon Sep 17 00:00:00 2001 From: eeleater Date: Mon, 16 Sep 2024 20:30:05 +0200 Subject: [PATCH 25/30] auto-notify.plugin.zsh aktualisiert --- auto-notify.plugin.zsh | 1 + 1 file changed, 1 insertion(+) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index d70cf79..f3f5d3d 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -62,6 +62,7 @@ function _auto_notify_message() { local arguments=("--title=$title" "--priority=$urgency" "$body") + echo "ntfy publish zsh_events ${arguments[@]}" ntfy publish zsh_events ${arguments[@]} } From 0a2b2f4601902cd89532707e2664645c31231261 Mon Sep 17 00:00:00 2001 From: eeleater Date: Mon, 16 Sep 2024 20:30:57 +0200 Subject: [PATCH 26/30] auto-notify.plugin.zsh aktualisiert --- 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 f3f5d3d..453cf71 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -62,7 +62,7 @@ function _auto_notify_message() { local arguments=("--title=$title" "--priority=$urgency" "$body") - echo "ntfy publish zsh_events ${arguments[@]}" + echo "ntfy publish zsh_events ${arguments[@]}" > /tmp/debug ntfy publish zsh_events ${arguments[@]} } From e9ca099379736ea066022a23b05366c23f89dbff Mon Sep 17 00:00:00 2001 From: eeleater Date: Mon, 16 Sep 2024 20:35:51 +0200 Subject: [PATCH 27/30] auto-notify.plugin.zsh aktualisiert --- auto-notify.plugin.zsh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index 453cf71..cab5a28 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -60,10 +60,9 @@ function _auto_notify_message() { icon=${AUTO_NOTIFY_ICON_FAILURE:-""} fi - local arguments=("--title=$title" "--priority=$urgency" "$body") + local arguments=("--title='$title'" "--priority='$urgency'" "zsh_events" "$body") - echo "ntfy publish zsh_events ${arguments[@]}" > /tmp/debug - ntfy publish zsh_events ${arguments[@]} + ntfy publish ${arguments[@]} } function _is_auto_notify_ignored() { From 81f516139041941c10d04f6bf4c9e6cbd99bc86f Mon Sep 17 00:00:00 2001 From: eeleater Date: Mon, 16 Sep 2024 20:37:27 +0200 Subject: [PATCH 28/30] auto-notify.plugin.zsh aktualisiert --- auto-notify.plugin.zsh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index cab5a28..7a3de94 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -50,17 +50,17 @@ function _auto_notify_message() { title="$(_auto_notify_format "$title" "$command" "$elapsed" "$exit_code")" body="$(_auto_notify_format "$text" "$command" "$elapsed" "$exit_code")" - local urgency="default" + local urgency="3" 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 # need to make the notification persistent. if [[ "$exit_code" != "0" ]] && [[ "$exit_code" != "130" ]]; then - urgency="high" + urgency="4" icon=${AUTO_NOTIFY_ICON_FAILURE:-""} fi - local arguments=("--title='$title'" "--priority='$urgency'" "zsh_events" "$body") + local arguments=("--title='$title'" "--priority=$urgency" "zsh_events" "$body") ntfy publish ${arguments[@]} } From 86deef4ded9e3ad99e7fe44a15112ba21ffb6661 Mon Sep 17 00:00:00 2001 From: eeleater Date: Mon, 16 Sep 2024 20:39:21 +0200 Subject: [PATCH 29/30] auto-notify.plugin.zsh aktualisiert --- 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 7a3de94..eba3065 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -62,7 +62,7 @@ function _auto_notify_message() { local arguments=("--title='$title'" "--priority=$urgency" "zsh_events" "$body") - ntfy publish ${arguments[@]} + ntfy publish -q ${arguments[@]} } function _is_auto_notify_ignored() { From f6c1f7fa356fac0d39c5ff3c4dcc5719e90f1714 Mon Sep 17 00:00:00 2001 From: eeleater Date: Mon, 16 Sep 2024 22:58:04 +0200 Subject: [PATCH 30/30] auto-notify.plugin.zsh aktualisiert --- auto-notify.plugin.zsh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/auto-notify.plugin.zsh b/auto-notify.plugin.zsh index eba3065..5daabd6 100644 --- a/auto-notify.plugin.zsh +++ b/auto-notify.plugin.zsh @@ -7,6 +7,9 @@ export AUTO_NOTIFY_VERSION="0.10.2" [[ -z "$AUTO_NOTIFY_THRESHOLD" ]] && export AUTO_NOTIFY_THRESHOLD=10 +[[ -z "$AUTO_NOTIFY_PUBLISH" ]] && + export AUTO_NOTIFY_PUBLISH="zsh_events" + # List of commands/programs to ignore sending notifications for [[ -z "$AUTO_NOTIFY_IGNORE" ]] && export AUTO_NOTIFY_IGNORE=( @@ -41,11 +44,13 @@ function _auto_notify_message() { local exit_code="$3" local platform="$(uname)" # Run using echo -e in order to make sure notify-send picks up new line - local DEFAULT_TITLE="ZSH: \"%command\" Completed" - local DEFAULT_BODY="$(echo -e "Total time: %elapsed seconds\nExit code: %exit_code")" + local DEFAULT_TITLE="ZSH: '%command' finished" + local DEFAULT_BODY="$(echo -e "Time: %elapsed seconds elapsed\nExit code: %exit_code")" + local DEFAULT_PUBLISH="zsh_events" local title="${AUTO_NOTIFY_TITLE:-$DEFAULT_TITLE}" local text="${AUTO_NOTIFY_BODY:-$DEFAULT_BODY}" + local publish="${AUTO_NOTIFY_PUBLISH:-$DEFAULT_PUBLISH}" title="$(_auto_notify_format "$title" "$command" "$elapsed" "$exit_code")" body="$(_auto_notify_format "$text" "$command" "$elapsed" "$exit_code")" @@ -60,7 +65,7 @@ function _auto_notify_message() { icon=${AUTO_NOTIFY_ICON_FAILURE:-""} fi - local arguments=("--title='$title'" "--priority=$urgency" "zsh_events" "$body") + local arguments=("--title='$title'" "--priority=$urgency" $publish "$body") ntfy publish -q ${arguments[@]} } @@ -161,11 +166,4 @@ function enable_auto_notify() { _auto_notify_reset_tracking - -platform="$(uname)" -if [[ "$platform" == "Linux" ]] && ! type notify-send > /dev/null; then - printf "'notify-send' must be installed for zsh-auto-notify to work\n" - printf "Please install it with your relevant package manager\n" -else - enable_auto_notify -fi +enable_auto_notify \ No newline at end of file