#!/bin/bash
function right-aligned() {
SPC=$(expr $(tput cols) - ${#1})
for (( j=1; j<=$SPC; j++ )); do
echo -n " ";
done;
echo -n ${1}
}
function fancy-timer() {
for (( i=1; i<=$1; i++ )); do
SEC=$(expr ${1} - $(expr ${i} - 1))
SECW="second"
if [ "$SEC" -ne "1" ]; then
SECW="${SECW}s"
fi
echo -ne "$(right-aligned "${2} ${SEC} ${SECW}")\r"
sleep 1
done;
}
# fancy-timer 10 "This example timer will end in"
# echo ""
Comments