#!/usr/bin/env osh
shopt -s strict:all
DEP="linuxconsoletools util-linux-misc"
DEC="Set a countdown timer to be alerted"
DOC="
Set a countdown timer after which expiry you'll be alerted.
Use the variable \$F_TIMER_PRESETS to set a space deliniated
array of strings suffixed by (h/m/s) that will prepopulate the
menu with time values.
"
VAR='
F_TIMER_PRESETS="10m 9m 8m 7m 6m 5m 4m 3m 2m 1m 30s 5s 1h"
'
terminate() {
setterm --inversescreen off
exit 0
}
timerrun() {
local ALERTTIME DATE
ALERTTIME=$(
echo "$@" |
sed 's#h#*60m#g'|
sed 's#m#*60s#g'|
sed 's#s#*1#g'|
sed 's# #+#g' |
bc
)
DATE="$(echo $(date +%s) + $ALERTTIME | bc)"
clear
while [ "$DATE" -ge "$(date +%s)" ]; do
printf %b "$(date -u --date @$((DATE - $(date +%s))) +%H:%M:%S) \r";
sleep 0.1
done
echo "Done with $*"
while true; do
pkill fftest
yes 5 | fftest /dev/input/by-path/platform-vibrator-event 2>&1 > /dev/null &
echo "Done with $*";
setterm --inversescreen on
sleep 0.2
setterm --inversescreen off
sleep 0.2
done
}
main() {
local TIME
trap terminate INT HUP TERM
env | grep -q "^$(basename "$0" | tr '[a-z]' '[A-Z]')=" || eval "$VAR"
clear
echo "Timer"
[ -p /tmp/fbp.fifo ] && { echo -e "\b\f\r"; echo "$F_TIMER_PRESETS" | tr " " "\n"; } > /tmp/fbp.fifo
read -p "Time (s, h, m): " TIME
timerrun "$TIME"
}
if [ -n "$1" ]; then "$@"; else main; fi