From 31ddf3a6d2e448be46dfe80b69a580687f1e9262 Mon Sep 17 00:00:00 2001 From: AnthonyAxenov Date: Mon, 10 Feb 2025 21:30:36 +0800 Subject: [PATCH] notification helpers --- helpers/notif.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 helpers/notif.sh diff --git a/helpers/notif.sh b/helpers/notif.sh new file mode 100644 index 0000000..2bd0e05 --- /dev/null +++ b/helpers/notif.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +######################################################## +# Notifications +######################################################## + +TITLE="$0" +NTFY_CHANNEL="example" + +# отправляет простую нотификацию +ntfy_info() { + require ntfy + ntfy send \ + --title "$TITLE" \ + --message "$1" \ + --priority 1 \ + "$NTFY_CHANNEL" +} + +# отправляет нотификацию с предупреждением +ntfy_warn() { + require ntfy + ntfy send \ + --title "$TITLE" \ + --tags "warning" \ + --message "$1" \ + --priority 5 \ + "$NTFY_CHANNEL" +} + + +notify () { + if ! installed "notify-send"; then + warning "Notifications toggled on, but 'notify-send' is not installed!" + return 1 + fi + [ -n "$1" ] && local title="$1" + local text="$2" + local level="$3" + local icon="$4" + case "$level" in + critical) local timeout=0 ;; + low) local timeout=5000 ;; + *) local timeout=10000 ;; + esac + debug "$title / $text / $level / $icon / $timeout" + notify-send "$title" "$text" -a "$0" -u "$level" -i "$icon" -t $timeout +} + +# TODO: docblock +notify_error() { + notify "Error" "$1" "critical" "dialog-error" +} + +# TODO: docblock +notify_warning() { + notify "Warning" "$1" "normal" "dialog-warning" +} + +# TODO: docblock +notify_info() { + notify "" "$1" "low" "dialog-information" +}