Compare commits

..

No commits in common. "master" and "fix/bad-icon-path" have entirely different histories.

2 changed files with 35 additions and 29 deletions

View file

@ -1,14 +1,6 @@
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

View file

@ -1,4 +1,4 @@
export AUTO_NOTIFY_VERSION="0.10.2"
export AUTO_NOTIFY_VERSION="0.10.0"
# Time it takes for a notification to expire
[[ -z "$AUTO_NOTIFY_EXPIRE_TIME" ]] &&
@ -7,9 +7,6 @@ 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=(
@ -44,30 +41,40 @@ 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' finished"
local DEFAULT_BODY="$(echo -e "Time: %elapsed seconds elapsed\nExit code: %exit_code")"
local DEFAULT_PUBLISH="zsh_events"
local DEFAULT_TITLE="\"%command\" Completed"
local DEFAULT_BODY="$(echo -e "Total time: %elapsed seconds\nExit code: %exit_code")"
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")"
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:-""}
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"
fi
local arguments=("--title='$title'" "--priority=$urgency" $publish "$body")
ntfy publish -q ${arguments[@]}
}
function _is_auto_notify_ignored() {
@ -166,4 +173,11 @@ function enable_auto_notify() {
_auto_notify_reset_tracking
enable_auto_notify
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