-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathalert.bash
41 lines (34 loc) · 1.1 KB
/
alert.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /usr/bin/env bash
HOOKS_ALERT_THRESHOLD="${HOOKS_ALERT_THRESHOLD:-60}"
hooks::alert_notify() {
[[ -z $2 ]] && return
title=$1
message=$2
if type terminal-notifier &>/dev/null; then
(terminal-notifier -title "$title" -message "$message" &)
elif [[ "$(uname -s)" == "Darwin" ]]; then
osascript -e "display notification \"$message\" with title \"$title\""
elif type ntfy &>/dev/null; then
if [[ -z $HOOKS_ALERT_NTFY_BACKEND ]]; then
(ntfy -t "$title" send "$message" &)
else
(ntfy -b "$HOOKS_ALERT_NTFY_BACKEND" -t "$title" send "$message" &)
fi
elif type notify-send &>/dev/null; then
(notify-send --icon=terminal "$title" "$message" &)
fi
}
hooks::alert() {
[[ $COMMAND_EXIT_CODE -lt 0 ]] && return
if [[ $HOOKS_ALERT_THRESHOLD -le $COMMAND_DURATION ]]; then
local title message
if [[ $COMMAND_EXIT_CODE -eq "0" ]]; then
title="Command Succeded"
message="Time spent was ${COMMAND_DURATION}s"
else
title="Command Failed"
message="Time spent was ${COMMAND_DURATION}s"
fi
hooks::alert_notify "$title" "$message"
fi
}