zsh: functions: add alarm function for quick alarms

master
bretello 2024-04-05 15:09:39 +02:00
parent 1ee73be7f9
commit faf318c3d0
Signed by: brethil
GPG Key ID: 876AAC6290170FE7
1 changed files with 24 additions and 0 deletions

View File

@ -69,6 +69,30 @@ function beeper
while true; do printf "\e[?5h\007"; sleep 0.25; printf "\e[?5l"; read -s -n -t1 && break; done;
}
# set an alarm in seconds, minutes, hours
function alarm {
if [[ -z $1 ]]; then
echo "Usage: alarm 5[s]|5m|1h"
return 1
fi
local t
if [[ $1 = *"m" ]]; then
t=$((${1/m/}*60))
extra="($1)"
elif [[ $1 = *"h" ]]; then
t=$((${1/h/}*3600))
extra="($1)"
elif [[ $1 = *"s" ]]; then
t=${1/s/}
else
t=$1
fi
echo "Setting a timer for $1 $extra"
sleep $t && beeper
}
## Simple http server for current directory (or path)
function httpserver