-
-
Save nonopolarity/ce234cceeafde27e0aba2dfa4ece47f6 to your computer and use it in GitHub Desktop.
simple stopwatch in bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add to your ~/.bashrc | |
function stopwatch() { | |
local BEGIN=$(date +%s) | |
while true; do | |
local NOW=$(date +%s) | |
local DIFF=$(($NOW - $BEGIN)) | |
local MINS=$(($DIFF / 60 % 60)) | |
local SECS=$(($DIFF % 60)) | |
local HOURS=$(($DIFF / 3600 % 24)) | |
local DAYS=$(($DIFF / 86400)) | |
local DAYS_UNIT | |
[ "$DAYS" == 1 ] && DAYS_UNIT="Day" || DAYS_UNIT="Days" | |
printf "\r %d %s, %02d:%02d:%02d " $DAYS $DAYS_UNIT $HOURS $MINS $SECS | |
sleep 0.25 | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment