Created
March 11, 2015 14:35
-
-
Save rawaludin/9c24bf900d798d66ce29 to your computer and use it in GitHub Desktop.
simple stopwatch in bash
This file contains 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
#!/bin/bash | |
function st() { | |
BEGIN=$(date +%s) | |
if [ -z "$1" ]; then | |
echo Starting Stopwatch... | |
else | |
echo $@... | |
fi | |
while true; do | |
NOW=$(date +%s) | |
let DIFF=$(($NOW - $BEGIN)) | |
let MINS=$(($DIFF / 60 % 60)) | |
let SECS=$(($DIFF % 60)) | |
let HOURS=$(($DIFF / 3600 % 24)) | |
let DAYS=$(($DIFF / 86400)) | |
# \r is a "carriage return" - returns cursor to start of line | |
printf "\e[36m\r%3d Days, %02d:%02d:%02d" $DAYS $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
isn't this going to contaminate the globals by introducing
NOW
,DIFF
,MINS
, etc? How about usinglocal NOW=$(date +%s)
etc?