: ' Changes:
Mon May 04 2026 Cahnges output to single line
Sun May 03 2026 Started script
'
[ "$1" == "-D" ] && DEBUG=1 && shift 1
[ "$DEBUG" == 1 ] && echo "---Variables---" && set -x
PS4='$SECONDS $LINENO: '
DOW=$(date +%a)
TODAY=$(date +%m/%d)
DOM=$(date +%d)
OS=$(uname -s)
NAME=${0##*/}
DIR="$(basename $PWD)"
PDIR="$(cd ..;basename $PWD)"
SIT=$(tput sitm)
RIT=$(tput ritm)
html(){
vim -f +"syn on" +"set nonu" +"set foldenable!" +"set nospell" +"run! syntax/2html.vim" +"wq" +"q" $1
}
log(){
[ "$DEBUG" == "1" ] && set -x
logger -i -t "$NAME" "$*"
}
xtitle(){
printf "\033]0;%s\007" "$*"
}
rcf() {
local fg=$(( (RANDOM % 6) + 1 ))
local bg=$(( (RANDOM % 6) + 1 ))
while [ $fg -eq $bg ]; do
bg=$(( (RANDOM % 6) + 1 ))
done
tput setaf $fg
tput setab $bg
tput bold
echo -n " $1 "
tput sgr0
}
countdown(){
local seconds=$1
while [ $seconds -gt 0 ]; do
printf "\r%02d:%02d:%02d " $((seconds/3600)) $(( (seconds/60)%60 )) $((seconds%60))
xtitle $(printf "\r%02d:%02d:%02d" $((seconds/3600)) $(( (seconds/60)%60 )) $((seconds%60)))
sleep 1
: $((seconds--))
done
[ $SOUND = "Y" ] && canberra-gtk-play -f /home/mitch/Music/sounds/system/alarm-clock-elapsed.oga
rcf "Time's up!"
}
if [ "$1" == "-E" ]
then
vim $0
sed -i -e "7s/.*/# Updated....: $(date)/" $0
log "Updated $0"
html $0
cp $0 /var/www/unix
mv $0.html /var/www/unix
exit
fi
if [ "$1" == "-h" ] || [ "$1" == "--help" ]
then
fmt -s -w $(tput cols) <<END
$NAME
Use:
timer {-s} {time} {"quoted text")
-s Play sound
Time formats:
23{s} Just a number or number with 's' is counted as seconds
23m If a 'm' is used it is counted a minutes
HH:MM:SS Can be used as well
- It will also change the window title to display count down.
END
exit
fi
command -v bash >/dev/null || sudo apt install bash -qyy
[ "$DEBUG" == 1 ] && echo "---Functions---" && typeset -F && read -p "${N}-Continue-" -n 1 x
[ "$DEBUG" == 1 ] && echo "---Main---" && set -x
if [ "$1" = "-s" ]
then
export SOUND=Y
shift
else
export SOUND=N
fi
case "$1" in
*":"*)
time_str="$1"
IFS=: read -r h m s <<< "$time_str"
SEC=$((10#$h * 3600 + 10#$m * 60 + 10#$s))
;;
*"m"*)
TRIM=$(echo $1 |sed 's/m//g')
SEC=$(( $TRIM * 60 ))
;;
*)
TRIM=$(echo $1 |sed 's/s//g')
SEC=$TRIM
;;
esac
countdown $SEC
[ "$#" -eq 2 ] && echo -e " ${SIT}${2}${RIT}" || echo ""
exit