#!/bin/sh # # get-timestamp - helper script to obtain a timestamp from the user # # Copyright © 2008 martin f. krafft # Released under the terms of the Artistic Licence 2.0 # set -eu if [ -z "${__RLWRAPPED:-}" ] && [ -x $(command -v rlwrap) ]; then __RLWRAPPED=true exec rlwrap "$0" "$@" fi printf 'When should I tickle you about this message? ' >/dev/tty read timespec &2 exit 1 ;; @[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]) date="$timespec";; [0-9][0-9][0-9][0-9][-.][0-9][0-9][-.][0-9][0-9]) date="$timespec";; *[0-9]y) date="now + ${timespec%y} years 00:00";; *[0-9]m) date="now + ${timespec%m} months 00:00";; *[0-9]w) date="now + ${timespec%w} weeks 00:00";; *[0-9]d|*[0-9]) date="now + ${timespec%d} days 00:00";; *[0-9]h) date="now + ${timespec%h} hours";; *) date="$timespec";; esac exec date +'%s (%c)' -d "$date"