Skip to content

Instantly share code, notes, and snippets.

@jasonleonhard
Created April 3, 2015 16:12
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 jasonleonhard/f2e38b91c791b2acdbe6 to your computer and use it in GitHub Desktop.
Save jasonleonhard/f2e38b91c791b2acdbe6 to your computer and use it in GitHub Desktop.
stopwatch or countdown
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