auto-notify.plugin.zsh aktualisiert

This commit is contained in:
eeleater 2024-09-16 22:58:04 +02:00
parent 86deef4ded
commit f6c1f7fa35

View file

@ -7,6 +7,9 @@ export AUTO_NOTIFY_VERSION="0.10.2"
[[ -z "$AUTO_NOTIFY_THRESHOLD" ]] && [[ -z "$AUTO_NOTIFY_THRESHOLD" ]] &&
export AUTO_NOTIFY_THRESHOLD=10 export AUTO_NOTIFY_THRESHOLD=10
[[ -z "$AUTO_NOTIFY_PUBLISH" ]] &&
export AUTO_NOTIFY_PUBLISH="zsh_events"
# List of commands/programs to ignore sending notifications for # List of commands/programs to ignore sending notifications for
[[ -z "$AUTO_NOTIFY_IGNORE" ]] && [[ -z "$AUTO_NOTIFY_IGNORE" ]] &&
export AUTO_NOTIFY_IGNORE=( export AUTO_NOTIFY_IGNORE=(
@ -41,11 +44,13 @@ 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="ZSH: \"%command\" Completed" local DEFAULT_TITLE="ZSH: '%command' finished"
local DEFAULT_BODY="$(echo -e "Total time: %elapsed seconds\nExit code: %exit_code")" 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 title="${AUTO_NOTIFY_TITLE:-$DEFAULT_TITLE}"
local text="${AUTO_NOTIFY_BODY:-$DEFAULT_BODY}" local text="${AUTO_NOTIFY_BODY:-$DEFAULT_BODY}"
local publish="${AUTO_NOTIFY_PUBLISH:-$DEFAULT_PUBLISH}"
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")"
@ -60,7 +65,7 @@ function _auto_notify_message() {
icon=${AUTO_NOTIFY_ICON_FAILURE:-""} icon=${AUTO_NOTIFY_ICON_FAILURE:-""}
fi fi
local arguments=("--title='$title'" "--priority=$urgency" "zsh_events" "$body") local arguments=("--title='$title'" "--priority=$urgency" $publish "$body")
ntfy publish -q ${arguments[@]} ntfy publish -q ${arguments[@]}
} }
@ -161,11 +166,4 @@ function enable_auto_notify() {
_auto_notify_reset_tracking _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