This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
/
rofi_notif_center.sh
executable file
·118 lines (104 loc) · 3.96 KB
/
rofi_notif_center.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
116
117
118
#!/usr/bin/env bash
#set -euo pipefail
##### Useful settings #####
# Directory to search for icons
directory="/usr/share/icons/Nord-Icon/48x48/"
#In case there is no icon path provided, use appname to guess icons
use_appname=true
###########################
### Raw data
raw=$(tac /tmp/dunstlog)
appname=$(echo -n "$raw" | sed -n '1~6p')
to_rofi=$(echo -n "$raw" | sed -n '2~6p;3~6p' | sed 's/\&/&/g')
icon=$(echo -n "$raw" | sed -n '4~6p' | while read -r line; do echo "$line"; done)
urgency=$(echo -n "$raw" | sed -n '5~6p')
timestamp=$(echo -n "$raw" | sed -n '6~6p')
### Create Icon list to parse through with rofi
while IFS= read -r i; do
if [[ -f "$i" ]]; then
full_path="$i\n"
elif [[ -n "$i" ]]; then
incomplete_icon_path=$(fd "$i" "$directory" | head -1)
full_path="${incomplete_icon_path}\n"
else
full_path="\n"
fi
icon_paths_list="${icon_paths_list}${full_path}"
done <<< "$icon"
### Create list of rows that are "active" i.e. low urgency for the -a flag on rofi
count=0
while IFS= read -r u; do
if [[ "$u" == *"LOW"* ]]; then
active_list=${active_list}${active_list:+,}$count
count=$((count+1))
else
count=$((count+1))
fi
done <<< "$urgency"
### Create list of urgent rows for rofi
count=0
while IFS= read -r u; do
if [[ "$u" == *"CRITICAL"* ]]; then
urgent_list=${urgent_list}${urgent_list:+,}$count
count=$((count+1))
else
count=$((count+1))
fi
done <<< "$urgency"
### Guess icon with appname
readarray -t app_array < <(echo -en "$appname")
app_array=( "${app_array[@],,}" )
##FIXME: if first notification doesnt have an icon path, notif center will only show latest notification. current workaround is to
##enable dunst startup notification
readarray -t icon_path_array < <(echo -en "$icon_paths_list")
if $use_appname; then
for i in "${!icon_path_array[@]}"; do
if [ -z "${icon_path_array[$i]}" ]; then
icon_path_array[$i]="${app_array[$i]}"
fi
done
fi
### Bold appname
readarray -t timestamp_array < <(echo -en "$timestamp")
count=0
while IFS= read -r a; do
app_spaces=$(printf %-42.42s "$a")
embolden_app="${embolden_app}${embolden_app:+\n}<b>$app_spaces</b>${timestamp_array[$count]}"
count=$((count+1))
done <<< "$appname"
### insert embolden appname
summary_line=0
body_line=1
readarray -t appname_array < <(echo -en "$embolden_app")
readarray -t to_rofi_array < <(echo -en "$to_rofi")
for a in "${appname_array[@]}"; do
app_merge="${app_merge}${app_merge:+\n}$a\n${to_rofi_array[$summary_line]}\n${to_rofi_array[$body_line]}"
summary_line=$((summary_line+2))
body_line=$((body_line+2))
done
### Insert icon paths
appname_line=0
summary_line=1
body_line=2
readarray -t merged_app_array < <(echo -en "$app_merge")
for i in "${icon_path_array[@]}"; do
merge="${merged_app_array[$body_line]}\\\0icon\\\x1f${i}"
amend="${amend}${amend:+\n}${merged_app_array[$appname_line]}\n${merged_app_array[$summary_line]}\n$merge"
appname_line=$((appname_line+3))
summary_line=$((summary_line+3))
body_line=$((body_line+3))
done
### Final prep
separation=$(sed '0~3 s/$/\x0f/g' <(echo -en "$amend"))
final_rofi=$(sed ':a;/\x0f$/{N;s/\n//;ba}' <(echo -n "$separation"))
### Eventual Final command to be executed
selection=$(echo -ne "$final_rofi" | rofi -markup-rows -theme ~/.config/rofi/configNotif.rasi -dmenu -eh 3 -a "$active_list" -u "$urgent_list" -sep '\x0f' -p "Notification Center" -no-fixed-num-lines -lines 8 -i -no-config)
### If a notification was selected, delete it from the logs
if [ -n "$selection" ]; then
remove_markup=$(echo -n "$selection" | sed -e 's/<[^>]*>//g')
extract_date="${remove_markup:42:8}"
remove_whitespace=$(echo -ne "$remove_markup" | sed '1~3 s/\s.*$//')
add_timestamp="$remove_whitespace\n.*\n.*\n$extract_date\n"
reverse_search=$(tac <(echo -ne "$add_timestamp") | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')
sed -i "N;N;N;N;N; /^$reverse_search$/d" /tmp/dunstlog
fi