Advertisement
zefie

fancy right-aligned countdown

Jan 10th, 2014
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.68 KB | None | 0 0
  1. #!/bin/bash
  2. function right-aligned() {
  3.         SPC=$(expr $(tput cols) - ${#1})
  4.         for (( j=1; j<=$SPC; j++ )); do
  5.                 echo -n " ";
  6.         done;
  7.         echo -n ${1}
  8. }
  9.  
  10. function fancy-timer() {
  11.                 for (( i=1; i<=$1; i++ )); do
  12.                         SEC=$(expr ${1} - $(expr ${i} - 1))
  13.                         SECW="second"
  14.                         if [ "$SEC" -ne "1" ]; then
  15.                                 SECW="${SECW}s"
  16.                         fi
  17.                         echo -ne "$(right-aligned "${2} ${SEC} ${SECW}")\r"
  18.                         sleep 1
  19.                 done;
  20. }
  21.  
  22. # fancy-timer 10 "This example timer will end in"
  23. # echo ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement