dotfiles/dotlib/post/calendar.sh

30 lines
1,018 B
Bash
Raw Normal View History

2024-05-13 09:06:43 +00:00
read -rd "" cal_events <<'EOF'
3,17,Saint Patrick's day,Happy,🍀
10,31,Halloween,Have a spooky,🎃
12,25,Christmas,Merry,🌲
*,Friday,Friday,Happy,🚀
EOF
if [[ -f ${XDG_CONFIG-"$HOME"/.config}/events.csv ]]; then
cal_events=$(< "${XDG_CONFIG-"$HOME"/.config}"/events.csv)
fi
read -r cur_{month,day} dow < <(date "+%m %d %A")
while IFS=, read -r ev_month ev_day ev celebrate sym; do
if [[ $ev_month = '*' ]] || (( 10#$cur_month == 10#$ev_month )); then
if [[ $ev_day = '*' || ${ev_day,,} = ${dow,,} ]]; then
printf -v ev_banner '%s %s!\n' "$celebrate" "${ev^}"
elif [[ $ev_day =~ ^[0-9]+$ ]] && (( 10#$cur_day == 10#$ev_day )); then
printf -v ev_banner '%s %s!\n' "$celebrate" "${ev^}"
elif [[ $ev_day =~ ^[0-9]+$ ]] && (( 10#$cur_day < 10#$ev_day )); then
printf -v ev_banner 'Only %d days until %s!\n' "$(( 10#$ev_day - 10#$cur_day ))" "${ev^}"
fi
if [[ -v ev_banner ]]; then
printf %s "$ev_banner"
prompt_symbol=$sym
fi
fi
done <<< "$cal_events"