auto-notify.plugin.zsh aktualisiert
Changed Plugin to use ntfy instead of notify-send, to send events to phone. Signed-off-by: eeleater <nikolasweger@googlemail.com>
This commit is contained in:
parent
27c07dddb4
commit
63f70f3c33
1 changed files with 13 additions and 30 deletions
|
@ -41,7 +41,7 @@ function _auto_notify_message() {
|
||||||
local exit_code="$3"
|
local exit_code="$3"
|
||||||
local platform="$(uname)"
|
local platform="$(uname)"
|
||||||
# Run using echo -e in order to make sure notify-send picks up new line
|
# 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 DEFAULT_BODY="$(echo -e "Total time: %elapsed seconds\nExit code: %exit_code")"
|
||||||
|
|
||||||
local title="${AUTO_NOTIFY_TITLE:-$DEFAULT_TITLE}"
|
local title="${AUTO_NOTIFY_TITLE:-$DEFAULT_TITLE}"
|
||||||
|
@ -50,36 +50,19 @@ function _auto_notify_message() {
|
||||||
title="$(_auto_notify_format "$title" "$command" "$elapsed" "$exit_code")"
|
title="$(_auto_notify_format "$title" "$command" "$elapsed" "$exit_code")"
|
||||||
body="$(_auto_notify_format "$text" "$command" "$elapsed" "$exit_code")"
|
body="$(_auto_notify_format "$text" "$command" "$elapsed" "$exit_code")"
|
||||||
|
|
||||||
if [[ "$platform" == "Linux" ]]; then
|
local urgency="default"
|
||||||
local urgency="normal"
|
local icon=${AUTO_NOTIFY_ICON_SUCCESS:-""}
|
||||||
local transient="--hint=int:transient:1"
|
# Exit code 130 is returned when a process is terminated with SIGINT.
|
||||||
local icon=${AUTO_NOTIFY_ICON_SUCCESS:-""}
|
# Since the user is already interacting with the program, there is no
|
||||||
# Exit code 130 is returned when a process is terminated with SIGINT.
|
# need to make the notification persistent.
|
||||||
# Since the user is already interacting with the program, there is no
|
if [[ "$exit_code" != "0" ]] && [[ "$exit_code" != "130" ]]; then
|
||||||
# need to make the notification persistent.
|
urgency="high"
|
||||||
if [[ "$exit_code" != "0" ]] && [[ "$exit_code" != "130" ]]; then
|
icon=${AUTO_NOTIFY_ICON_FAILURE:-""}
|
||||||
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"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local arguments=("--title=$title" "--priority=$urgency" "$body")
|
||||||
|
|
||||||
|
ntfy publish zsh_events ${arguments[@]}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _is_auto_notify_ignored() {
|
function _is_auto_notify_ignored() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue