diff --git a/scripts/stopwatch b/scripts/stopwatch new file mode 100755 index 00000000..0d9845f5 --- /dev/null +++ b/scripts/stopwatch @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +stopwatch() { + start=$(date +%s) + while true; do + days="$(($(( $(date +%s) - $start )) / 86400))" + time="$(( $(date +%s) - $start ))" + printf '%s day(s) and %s\r' "$days" "$(date -u -d "@$time" +%H:%M:%S)" + sleep 0.1 + done +} + +stopwatch "${@}" + +# countdown() { + # start="$(( $(date +%s) + $1))" + # while [ "$start" -ge $(date +%s) ]; do + # ## Is this more than 24h away? + # days="$(($(($(( $start - $(date +%s) )) * 1 )) / 86400))" + # time="$(( $start - `date +%s` ))" + # printf '%s day(s) and %s\r' "$days" "$(date -u -d "@$time" +%H:%M:%S)" + # sleep 0.1 + # done +# } + +# Taken from: +# https://superuser.com/questions/611538/is-there-a-way-to-display-a-countdown-or-stopwatch-timer-in-a-terminal