Skip to content

Instantly share code, notes, and snippets.

@ephemient
Created October 16, 2015 02:48
Show Gist options
  • Save ephemient/2e21838cff520f2cf71c to your computer and use it in GitHub Desktop.
Save ephemient/2e21838cff520f2cf71c to your computer and use it in GitHub Desktop.
delay
#!/bin/bash -e
WHEN=${1}
shift
if [[ -z ${WHEN} ]]; then
echo "Usage: ${0} <date/time format> [program]"
exit 1
fi
TARGET=$(date -d "${WHEN}" +%s)
echo "Terminating on $(date -d "@${TARGET}")"
while :; do
NOW=$(date +%s)
((NOW>TARGET)) && break
T=$((TARGET-NOW))
: "${FMT:=%$(awk '{print length}' <<<"$((T/3600))")d:%02d:%02d}"
printf "\rExpires in: $FMT" $((T/3600)) $((T/60%60)) $((T%60))
sleep 1
done
echo
(($#)) && exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment