From 43dbc4eb566bf6eed0c390028a75e2359ac40e6f Mon Sep 17 00:00:00 2001 From: Michael Aquilina Date: Mon, 13 May 2024 10:54:40 +0100 Subject: [PATCH 01/12] 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 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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 07/12] 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 08/12] 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 09/12] 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 10/12] 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 11/12] 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 12/12] 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