-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstantnotify.sh
executable file
·115 lines (93 loc) · 3.02 KB
/
instantnotify.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
#######################################
## notification center for instantOS ##
#######################################
# show notification history in instantmenu
# enter to open a submenu for reading and deleting
# esc to exit
if ! [ -e /tmp/notifications/notif.txt ]; then
echo "creating notification dir"
mkdir /tmp/notifications
cd /tmp/notifications || exit 1
echo "press enter to open submenu" >notif.txt
fi
cd /tmp/notifications || exit 1
NOTIFCOUNT="$(instantnotifyctl ca)"
PAGECOUNT="$((NOTIFCOUNT / 700))"
NOTIFPAGE="$PAGECOUNT"
notifmenu() {
NOTIFICATIONLIST="$(
instantnotifyctl l "$NOTIFPAGE" | sed 's/\(.*\);:;\(.*\);:;\(.*\);:;\(.*\);:;\(.*\)/:b \5 [\1] (\2) *\3* \4/g' | sed 's/^:b 0/:r /g' | sed 's/^:b 1/:b /g' | tac
)"
CHOICE="$(
{
if [ "$NOTIFPAGE" -lt "$PAGECOUNT" ]; then
echo ':g Previous page'
fi
cut -c-500 <<<"$NOTIFICATIONLIST"
if [ "$NOTIFPAGE" -gt 0 ]; then
echo ':g Next page'
fi
} | instantmenu -i -c -l 18 -h -1 -p "notifications" -lc "instantnotifyoptions" -q "search notifications" -bw 4 -a 4
)"
if [ ':g Next page' = "$CHOICE" ]; then
NOTIFPAGE="$((NOTIFPAGE - 1))"
notifmenu
return
elif [ "$CHOICE" = ':g Previous page' ]; then
NOTIFPAGE="$((NOTIFPAGE + 1))"
notifmenu
return
elif [ -z "$CHOICE" ]; then
exit
else
OUTCHOICE="$(grep -F "$CHOICE" <<<"$NOTIFICATIONLIST" | head -1 | grep -o '\[.*')"
echo "$OUTCHOICE"
fi
}
refreshmenu() {
NREAD=$(notifmenu)
MESSAGE="$(echo "$NREAD" | grep -o '.*' | grep -o '[^]*')"
TITLE="$(echo "$NREAD" | grep -o '.*' | grep -o '\*.*\*' | grep -o '[^*]*')"
echo "title: $TITLE"
READMESSAGE="$(echo "$MESSAGE" | sed -e 's/.\{50\}/&\n/g' | sed 's/^/> /g')"
}
refreshmenu
while [ -n "$NREAD" ]; do
# wrap lines and filter out lines that are not notifications
read -r SELECTION < <({
echo "$NREAD" | grep -o '\[.*' | sed -e "s/.\{150\}/&\n/g" |
sed 's/\[\([0-9]*:[0-9]*\)\] (\(.*\)) \*\(.*\)\* \(.*\)/:g Application : \2\n> \1\n> \3/g'
echo "$READMESSAGE
> "
echo ':b Back
:b Mark as unread
:r Delete
:y Close'
} | instantmenu -lc "instantnotifyoptions" -c -l 18 -h -1 -q "notification" -bw 4 -a 4)
[ "$SELECTION" = ":b Mark as unread" ] || instantnotifyctl r "$MESSAGE" "$TITLE"
[ -z "$SELECTION" ] && exit
case "$SELECTION" in
*Delete)
instantnotifyctl d "$MESSAGE" "$TITLE"
;;
*Close)
exit
;;
*Back)
echo "back"
;;
*unread)
echo "marking as unread"
instantnotifyctl u "$MESSAGE" "$TITLE"
;;
*)
echo "app"
SELECTION2="${SELECTION#:g Application : }"
echo "focussing $SELECTION2"
wmctrl -x -a "$SELECTION2"
exit
;;
esac
refreshmenu
done