diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d36ffe..400999d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ 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) + 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..5daabd6 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.2" # Time it takes for a notification to expire [[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] && @@ -7,6 +7,9 @@ export AUTO_NOTIFY_VERSION="0.10.0" [[ -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,40 +44,30 @@ 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_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")" - 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 - 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" - fi - - 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="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="4" + icon=${AUTO_NOTIFY_ICON_FAILURE:-""} fi + + local arguments=("--title='$title'" "--priority=$urgency" $publish "$body") + + ntfy publish -q ${arguments[@]} } function _is_auto_notify_ignored() { @@ -173,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