sane-deadlines: allow specifying the amount of desired notice per-deadline
This commit is contained in:
parent
c94ed9d519
commit
8ae4be341a
|
@ -3,38 +3,41 @@
|
||||||
# processes a tab-separated "deadlines" file and alerts for any upcoming events.
|
# processes a tab-separated "deadlines" file and alerts for any upcoming events.
|
||||||
#
|
#
|
||||||
# deadlines.tsv file format:
|
# deadlines.tsv file format:
|
||||||
# - <date>\t<event>
|
# - <date>\t<reminder-interval>\t<event>
|
||||||
# - no header
|
# - no header
|
||||||
# - one line per entry
|
# - one line per entry
|
||||||
# - <event> may contain any non-newline and non-tab characters
|
# - <event> may contain any non-newline and non-tab characters
|
||||||
|
# - <notice-interval> is the number of days before the event to start alerting, followed by 'd', e.g. `14d`
|
||||||
# - <date> should be lexicographically orderable and machine-parsable, e.g. `2023-03-14`
|
# - <date> should be lexicographically orderable and machine-parsable, e.g. `2023-03-14`
|
||||||
#
|
#
|
||||||
# example `deadlines.tsv`
|
# example `deadlines.tsv`
|
||||||
# 2023-03-14 celebrate pi day!
|
# 2023-03-14 1d celebrate pi day!
|
||||||
# 2023-04-18 taxes due
|
# 2023-04-18 14d taxes due
|
||||||
# 2023-04-01 the other pie day :o
|
# 2023-04-01 7d the other pie day :o
|
||||||
|
|
||||||
# configurables:
|
# configurables:
|
||||||
deadlines=~/knowledge/planner/deadlines.tsv
|
deadlines=~/knowledge/planner/deadlines.tsv
|
||||||
threshold_in_days=14 # only show events happening within this many days
|
|
||||||
|
|
||||||
if ! test -f "$deadlines"; then
|
if ! test -f "$deadlines"; then
|
||||||
echo "WARNING: $deadlines sane-deadlines file not found"
|
echo "WARNING: $deadlines sane-deadlines file not found"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
today=$(date +%s)
|
now=$(date +%s)
|
||||||
sort "$deadlines" | while read line; do
|
sort "$deadlines" | while read line; do
|
||||||
# parse line
|
# parse line
|
||||||
date_field=$(echo "$line" | cut -f 1)
|
deadline_field=$(echo "$line" | cut -f 1)
|
||||||
event=$(echo "$line" | cut -f 2)
|
threshold_field=$(echo "$line" | cut -f 2)
|
||||||
|
description_field=$(echo "$line" | cut -f 3)
|
||||||
|
|
||||||
# compute temporal distance
|
# normalize dates into seconds since unix epoch
|
||||||
date=$(date -d "$date_field" +%s)
|
deadline=$(date -d "$deadline_field" +%s)
|
||||||
days_until=$(( ($date - $today) / (24*60*60) ))
|
threshold=$(echo "$threshold_field" | sed 's/d/day /g')
|
||||||
|
birthtime=$(date -d "$deadline_field - ($threshold)" +%s)
|
||||||
|
|
||||||
# show the event iff it's near
|
# show the event iff it's near
|
||||||
if test "$days_until" -lt "$threshold_in_days"; then
|
if test "$now" -ge "$birthtime"; then
|
||||||
echo "$days_until days until $event"
|
days_until=$(( ($deadline - $now) / (24*60*60) ))
|
||||||
|
echo "in $days_until day(s): $description_field"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in New Issue
Block a user