Files
dotfiles/.config/xmobar/calcurse.sh
T
Daniele Fucini 409bebaa52 calcurse: show tomorrow's whole-day events in xmobar, notify at 07:00
A grey icon for a whole-day event tomorrow when nothing else is due; calcurse-today runs at 07:00
and pulls in a sync first. Same change as calcurse-gcal b785416.
2026-11-23 20:55:52 +01:00

46 lines
1.7 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Next calcurse item for xmobar: pink " 10:15 | " for an appointment later today, a cyan icon for a whole-day
# event today, a pink icon alone when the next appointment is tomorrow, a grey icon for a whole-day event tomorrow;
# empty otherwise.
# With "list": show today's and tomorrow's items in a notification (for a click on the bar)
set -uo pipefail
icon=$'\xf3\xb0\x83\xad' # nf-md-calendar, as UTF-8 bytes so the locale doesn't matter
today=$(date +%F)
query() {
calcurse -Q --filter-type cal --days 2 --output-datefmt %F "$@"
}
if [[ ${1:-} == list ]]; then
tomorrow=$(date -d tomorrow +%F)
body=$(query --format-apt '%S–%E %m\n' --format-recur-apt '%S–%E %m\n' \
--format-event 'all day %m\n' --format-recur-event 'all day %m\n' |
sed -e 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g' -e "s/^$today:$/Today:/; s/^$tomorrow:$/Tomorrow:/")
notify-send -a calcurse -i x-office-calendar "Calendar" "${body:-Nothing today or tomorrow}"
exit
fi
now=$(date +%s)
day="" next="" event_today=false event_tomorrow=false
while read -r kind start; do
case $kind in
*:) day=${kind%:} ;;
A) [[ -z $next ]] && ((start > now)) && next=$start ;;
E) if [[ $day == "$today" ]]; then event_today=true; else event_tomorrow=true; fi ;;
esac
done < <(query --format-apt 'A %s\n' --format-recur-apt 'A %s\n' --format-event 'E\n' --format-recur-event 'E\n')
if [[ -n $next && $(date -d "@$next" +%F) == "$today" ]]; then
text="<fc=#ff79c6>$icon $(date -d "@$next" +%H:%M)</fc>"
elif $event_today; then
text="<fc=#8be9fd>$icon</fc>"
elif [[ -n $next ]]; then
text="<fc=#ff79c6>$icon</fc>"
elif $event_tomorrow; then
text="<fc=#565f89>$icon</fc>"
else
exit 0
fi
echo "$text | "