#!/usr/bin/env bash usage() { echo "at - exit after the specified datetime" echo "Usage:" echo " at && command..." echo echo "Examples:" echo " at 15:00:00 && echo \"it is 3 o'clock\"" } [[ -z "$1" ]] && { echo "error: no DATE argument provided" >&2; usage; exit 1; } d="$(date -d "${*}" +%s)" # If parsed time is in the past and input looks like just a time, assume tomorrow if [[ "$d" -lt "$(date +%s)" ]] && [[ "${*}" =~ ^[0-9]{1,2}:[0-9]{2}(:[0-9]{2})?$ ]]; then d="$(date -d "tomorrow ${*}" +%s)" fi _dt=$((d - $(date +%s))) days=$((_dt / 86400)) printf 'Started at %s (with duration %sd %s)\n' "$(date)" "$days" "$(date -u --date @$((_dt)) +%H:%M:%S)" while [[ "$d" -ge "$(date +%s)" ]]; do _dt=$((d - $(date +%s))) days=$((_dt / 86400)) printf "\r%sd %s " "$days" "$(date -u --date @$((_dt)) +%H:%M:%S)"; sleep 0.1 done exit 0