Add simple_timer

This commit is contained in:
tosu 2024-12-16 14:32:15 +01:00
parent 6a2f012a99
commit 2debe6ee7c
No known key found for this signature in database
1 changed files with 29 additions and 0 deletions

29
.local/bin/simple_timer Executable file
View File

@ -0,0 +1,29 @@
#! /bin/sh -
min="${1-}"
sec="${2-}"
if [ -z "${min}" ] || [ -z "${sec}" ] || [ -n "${3-}" ] ; then
printf '%s\n' "Usage: ${0-} MIN SEC"
exit 1
fi
print_as_minutes () {
_total_sec="${1}"
min="$((_total_sec / 60))"
sec="$((_total_sec % 60))"
clear -x
n_lines="$(($(tput lines) / 2 - 4))"
while [ "${n_lines}" -ge "0" ] ; do
printf '\n'
n_lines="$((n_lines - 1))"
done
figlet -w "$(tput cols)" -c "${min} : ${sec}"
}
total_sec="$((min * 60 + sec))"
while [ "${total_sec}" -ge "0" ] ; do
print_as_minutes "${total_sec}"
sleep 1s
total_sec="$((total_sec - 1))"
done