#!/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