calendargen

#!/bin/sh
# outputs a list of periodic calendar entries for use with calendar(1)
# example usage: calendargen 'Install Gentoo!' -t now -d 14 | head -n8
# © 2014 Nils Dagsson Moskopp (erlehmann) – license: GPLv3+
date=$(date +%Y-%m-%d)
days=1
note=$1; shift

while getopts d:t: OPT; do
  case $OPT in
    d) days="$OPTARG";;
    t) date="$OPTARG";;
  esac
done

if [ "$(date --date="$date" +%H:%M)" = "00:00" ]; then
  dateopts='+%Y-%m-%d'
else
  dateopts='+%Y-%m-%d %H:%M'
fi

ts=$(date +%s --date="$date")
test -z "$ts" && exit 1

while true; do
  date=$(date --date=@$ts "$dateopts")
  test -z "$date" && break
  printf '%s\t%s\n' "$date" "$note"
  ts=$(expr $ts + '(' 86400 '*' $days ')' )
done