new sane-deadlines tool to remind me of upcoming deadlines

This commit is contained in:
Colin 2023-03-08 01:09:24 +00:00
parent 98739bb061
commit 99373dcd83

View File

@ -0,0 +1,40 @@
#!/usr/bin/env bash
# processes a tab-separated "deadlines" file and alerts for any upcoming events.
#
# deadlines.tsv file format:
# - <date>\t<event>
# - no header
# - one line per entry
# - <event> may contain any non-newline and non-tab characters
# - <date> should be lexicographically orderable and machine-parsable, e.g. `2023-03-14`
#
# example `deadlines.tsv`
# 2023-03-14 celebrate pi day!
# 2023-04-18 taxes due
# 2023-04-01 the other pie day :o
# configurables:
deadlines=~/knowledge/planner/deadlines.tsv
threshold_in_days=14 # only show events happening within this many days
if ! test -f "$deadlines"; then
echo "WARNING: $deadlines sane-deadlines file not found"
exit 1
fi
today=$(date +%s)
sort "$deadlines" | while read line; do
# parse line
date_field=$(echo "$line" | cut -f 1)
event=$(echo "$line" | cut -f 2)
# compute temporal distance
date=$(date -d "$date_field" +%s)
days_until=$(( ($date - $today) / (24*60*60) ))
# show the event iff it's near
if test "$days_until" -lt "$threshold_in_days"; then
echo "$days_until days until $event"
fi
done