mirror of
https://git.decapod.one/brethil/dotfiles
synced 2024-11-21 19:11:30 +01:00
zsh: alarm: add elapsed time
This commit is contained in:
parent
f414792552
commit
4b457a022c
|
@ -75,22 +75,46 @@ function alarm {
|
|||
echo "Usage: alarm 5[s]|5m|1h"
|
||||
return 1
|
||||
fi
|
||||
value=$1
|
||||
|
||||
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/}
|
||||
if [[ $value = *"m" ]]; then
|
||||
t=$((${value/m/}*60))
|
||||
elif [[ $value = *"h" ]]; then
|
||||
t=$((${value/h/}*3600))
|
||||
elif [[ $value = *"s" ]]; then
|
||||
t=${value/s/}
|
||||
else
|
||||
t=$1
|
||||
t=$value
|
||||
fi
|
||||
|
||||
echo "Setting a timer for $1 $extra"
|
||||
function format(){
|
||||
if [[ $1 -lt 60 ]]; then
|
||||
printf "00:%02is" $1
|
||||
return
|
||||
fi
|
||||
|
||||
sleep $t && beeper
|
||||
if [[ $1 -lt 3600 ]]; then
|
||||
minutes=$(($1/60))
|
||||
seconds=$(($1%60))
|
||||
printf "%02dm:%02dm" $minutes $seconds
|
||||
return
|
||||
fi
|
||||
|
||||
hours=$(($1/3600))
|
||||
remainder=$(($1%3600))
|
||||
printf "%dh:%s" hours "$(format $remainder)"
|
||||
}
|
||||
|
||||
count=$t
|
||||
while [[ $count -ge 0 ]]; do
|
||||
echo -en "Set a timer for $1 │ remaining=$(format $count)"
|
||||
count=$((count-1))
|
||||
sleep 1
|
||||
echo -en "\r"
|
||||
done
|
||||
echo -e "\nDone!"
|
||||
beeper
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user