Created
April 3, 2015 16:12
-
-
Save jasonleonhard/f2e38b91c791b2acdbe6 to your computer and use it in GitHub Desktop.
stopwatch or countdown
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
countdown() { | |
[[ -z $1 ]] && seconds=60 || seconds=$1 | |
since=$(date +%s) | |
remaining=$seconds | |
while (( remaining >= 0 )) | |
do | |
printf "\r%-10d" $remaining | |
sleep 0.5 | |
remaining=$(( seconds - $(date +%s) + since )) | |
done | |
$2 # can specify a command to do at the end of the countdown | |
# for instance: countdown 3 lt | |
# or: countdown 3 'lt mar' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment