-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathb-calendar
executable file
·76 lines (67 loc) · 1.85 KB
/
b-calendar
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
#!/usr/bin/env bash
calcurse_filter_between() {
local start="$1"
local end="$2"
calcursed -G --filter-type=apt --filter-start-from="$start" --filter-end-to="$end"
}
dateoffset() {
local dt="$1"
local dt_offset="$2"
local -a args=("+$dt")
if [[ -n "$dt_offset" ]]; then
args+=(-d "$dt_offset")
fi
date "${args[@]}"
}
notify_text() {
calcurse_filter_between "$(dateoffset '%m/%d/%Y %H:%M')" "$(dateoffset '%m/%d/%Y' '+1 day')" | tr '|' '\n'
}
case "$BLOCK_BUTTON" in
1)
# send a notification with todays appointments
notify "$(notify_text)"
;;
3)
# open calcurse in my terminal
# https://purarue.xyz/d/cross-platform/launch?dark
launch calcursed
;;
esac
calcurse_status() {
# Find things on my calendar that are starting after now, today
# and meetings that are on my calendar, at any time today
today_coming_up="$(calcurse_filter_between "$(dateoffset '%m/%d/%Y %H:%M')" "$(dateoffset '%m/%d/%Y')" | wc -l)"
tomorrow="$(calcurse_filter_between "$(dateoffset '%m/%d/%Y' '+1 day')" "$(dateoffset '%m/%d/%Y' '+1 day')" | wc -l)"
if ((today_coming_up == 0 && tomorrow == 0)); then
echo 0
# if today is zero, just 0/tomorrow
elif ((today_coming_up == 0)); then
printf '0/%s\n' "$tomorrow"
else
# today_coming_up > 0 in this case
if ((tomorrow > 0)); then
# print items upcoming / total items today
printf '%s/%s\n' "$today_coming_up" "$tomorrow"
else
printf '%s\n' "$today_coming_up"
fi
fi
}
if [[ -z "$CALCURSE_DIR" ]]; then
# shellcheck disable=SC2016
notify 'No $CALCURSE_DIR set'
exit 1
fi
caltext() {
SYNC_CONFLICTS="$(sync-conflicts "$CALCURSE_DIR" 2>/dev/null | wc -l)"
if [[ "$SYNC_CONFLICTS" -gt 0 ]]; then
printf "%s \n" "$(calcurse_status)"
else
calcurse_status
fi
}
if [[ -n "${STATUS_JSON:-}" ]]; then
jq -rcn --arg text "$(caltext)" --arg hover "$(notify_text)" '{"text": $text, "tooltip": $hover}'
else
caltext
fi