nix/modules/home-manager/scripts/common/bin/at

26 lines
650 B
Text
Raw Normal View History

2023-09-05 13:52:52 -05:00
#!/usr/bin/env bash
usage() {
2024-04-26 11:35:28 -05:00
echo "at - exit after the specified datetime"
2023-09-05 13:52:52 -05:00
echo "Usage:"
echo " at <DATETIME> && command..."
echo
echo "Examples:"
echo " at 15:00:00 && echo \"it is 3 o'clock\""
}
2024-04-26 11:35:28 -05:00
[[ -z "$1" ]] && { echo "error: no DATE argument provided" >&2; usage; exit 1; }
2023-09-05 13:52:52 -05:00
d="$(date -d "${@}" +%s)"
2024-04-26 11:35:28 -05:00
_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)"
2023-09-05 13:52:52 -05:00
while [[ "$d" -ge "$(date +%s)" ]]; do
_dt=$((d - $(date +%s)))
days=$((_dt / 86400))
2024-04-26 11:35:28 -05:00
printf "\r%sd %s " "$days" "$(date -u --date @$((_dt)) +%H:%M:%S)";
2023-09-05 13:52:52 -05:00
sleep 0.1
done
2024-04-26 11:35:28 -05:00
exit 0