-
Notifications
You must be signed in to change notification settings - Fork 0
/
b-calendar
executable file
·57 lines (50 loc) · 1.51 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
#!/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[@]}"
}
case "$BLOCK_BUTTON" in
1)
# send a notification with todays appointments
notify "$(calcurse_filter_between "$(dateoffset '%m/%d/%Y %H:%M')" "$(dateoffset '%m/%d/%Y' '+1 day')" | tr '|' '\n')"
;;
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 all are upcoming (later in the day), just print one
if ((tomorrow == today_coming_up)); then
printf '%s\n' "$today_coming_up"
else
# print items upcoming / total items today
printf '%s/%s\n' "$today_coming_up" "$tomorrow"
fi
}
if [[ -z "$CALCURSE_DIR" ]]; then
# shellcheck disable=SC2016
notify 'No $CALCURSE_DIR set'
exit 1
fi
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