-
Notifications
You must be signed in to change notification settings - Fork 3
/
matterhorn_notification.sh
executable file
·66 lines (52 loc) · 1.51 KB
/
matterhorn_notification.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env bash
# Sample shell script for using notify-send with matterhorn This script
# works on Linux only. It depends on the 'notify-send' command.
# Positional parameters passed to this script by Matterhorn:
mentioned="${1?}"
sender="${2?}"
message="${3?}"
# Script options
# notify_URGENCIES
#
# The first word is the urgency for items where you are not mentioned.
# The second word is the urgency for items where you are mentioned.
# Use "none" to not be notified; otherwise use "low", "normal", or
# "critical".
notify_URGENCIES="normal normal"
# The desktop notification category
notify_CATEGORY="im.received"
# Notification header
notify_HEAD="$sender"
# Notification body
notify_BODY="$message"
getUrgencyHelper() {
if [ "$mentioned" == "1" ]
then
echo "$1"
else
if [ "$mentioned" == "2" ]
then
echo "$2"
else
echo "Error: mentioned value '$mentioned' unexpected" > /dev/stderr
exit 1
fi
fi
}
getUrgency() {
# We are using arguments as a poor man's bash array for portability
# shellcheck disable=SC2086
getUrgencyHelper $notify_URGENCIES
}
urgency=$(getUrgency)
printf -v NOW '%(%Y-%m-%d %H:%M:%S)T' -1
echo "$NOW: $@" >> ~/.matterhon_notifications
if [[ "$message" == *":clockify:"* ]]; then
echo "$NOW: $@" >> ~/.matterhon_clockify
exit
fi
if [ ! -z "$urgency" ]
then
test "$urgency" = "none" ||
terminal-notifier -subtitle "$notify_HEAD:" -title "Matterhorn" -message "$notify_BODY"
fi