Skip to content

Instantly share code, notes, and snippets.

@nonopolarity
Forked from rawaludin/stopwatch.sh
Last active July 31, 2017 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nonopolarity/ce234cceeafde27e0aba2dfa4ece47f6 to your computer and use it in GitHub Desktop.
Save nonopolarity/ce234cceeafde27e0aba2dfa4ece47f6 to your computer and use it in GitHub Desktop.
simple stopwatch in bash
# 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