!/bin/sh

agenda - display a range of days from agenda.txt files

SPDX-FileCopyrightText: 2023 Daniel Kalak

SPDX-License-Identifier: GPL-3.0-or-later

This program expects the specified files to be in the format described

on https://github.com/brvier/MOrg#agendatxt-format. The program

reports non-conforming lines on stderr. Environment variables are not

checked; use aliases for preferences. The program exits 1 on bad usage

and 0 otherwise (even if there are non-conforming lines).

usage_quit() {

cat <<- EOF >&2

Usage:

    $(basename "$0") BEGIN END FILE...

Format of BEGIN and END:

    YYYY-mm-dd: the given date

    -N: N days before today

    +N: N days after today

EOF

exit 1

}

get_date() {

case "$1" in

[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])

	printf %s "$1" | tr -d -

	;;

''|[!+-]*|[+-]*[!0-9]*)

	return 1

	;;

*)

	date -I -d "$1 days" | tr -d -

	;;

esac

}

[ "$#" -lt 3 ] && usage_quit

begin="$(get_date "$1")" || usage_quit

end="$(get_date "$2")" || usage_quit

shift 2

cat "$@" | grep -v -e '^#' -e '^$' | while read -r date line

do

case "$date" in

[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9])

	numdate="$(printf %s "$date" | tr -d -)"

	;;

*)

	printf 'Invalid date: %s\n' "$date" >&2

	continue

	;;

esac

[ "$numdate" -lt "$begin" ] || [ "$numdate" -gt "$end" ] && continue

printf '%s %s\n' "$date" "$line"

done | LC_ALL=C sort

Proxy Information
Original URL
gemini://dkalak.de/software/agenda.sh
Status Code
Success (20)
Meta
text/plain
Capsule Response Time
108.061315 milliseconds
Gemini-to-HTML Time
1.235676 milliseconds

This content has been proxied by September (ba2dc).