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

25 lines
628 B
Text
Raw Permalink Normal View History

2023-09-05 13:52:52 -05:00
#!/usr/bin/env bash
2024-04-26 11:35:28 -05:00
function usage {
echo "countdown - exit after a certain amount of time has passed"
echo " Usage:"
echo " countdown <SECONDS> && command..."
echo
echo " Examples:"
echo ' countdown 120 && echo "Two minutes has elapsed!"'
}
[[ $# -lt 1 ]] && { printf "error: no SECONDS argument provided\n" >&2; usage; exit 1; }
2023-09-05 13:52:52 -05:00
d=$(($(date +%s) + $1));
2024-04-26 11:35:28 -05:00
printf 'Started at %s\n' "$(date)"
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
printf "\rCountdown finished %s\n" "$(date)"