64 lines
1.4 KiB
Bash
64 lines
1.4 KiB
Bash
#!/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"
|
||
}
|