#!/bin/sh

#i3blocks calcurse module

case $BUTTON in
	3)notify-send -t 5000 "$(calcurse -D ~/.config/calcurse/ -c ~/.config/calcurse/apts -a)";;
	1)notify-send -t 20000 "$(calcurse -D ~/.config/calcurse/ -c ~/.config/calcurse/apts -r7)";;
	2)notify-send -t 5000 "$(calcurse -D ~/.config/calcurse/ -t)"
esac

name="$(calcurse -D ~/.config/calcurse/ -c ~/.config/calcurse/apts -n | grep "\[" | sed "s/\s*\[/\[/" | cut -d ' ' -f 2-)"
[ "$name" = "" ] && echo "Nothing Scheduled" && exit 0
time="$(grep "$name" ~/.config/calcurse/apts | head -1 | cut -d ' ' -f 3)"
[ ${time%%:*} -gt 12 ] && time="$((${time%%:*}-12)):${time##*:} PM" || time="$time AM"
echo "$name @ $time"