From e1a511b577989d61b5f3fecc13ae386a1e776c8c Mon Sep 17 00:00:00 2001 From: tiyn Date: Thu, 26 Oct 2023 04:29:54 +0200 Subject: [PATCH] tools: timer script improved --- .local/bin/tools/timer | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.local/bin/tools/timer b/.local/bin/tools/timer index 1170ada..24b0e16 100755 --- a/.local/bin/tools/timer +++ b/.local/bin/tools/timer @@ -8,11 +8,16 @@ usage: timer [option] [args] -h Display this message """ +max_seconds=86400 countdown() { start="$(( $(date '+%s') + $1))" while [ $start -ge $(date +%s) ]; do time="$(( $start - $(date +%s) ))" + if [ $time -ge $max_seconds ]; then + echo "Maximum number of seconds ($max_seconds) for countdown surpassed." + exit + fi printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)" sleep 0.1 done @@ -23,6 +28,10 @@ stopwatch() { while true; do time="$(( $(date +%s) - $start))" printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)" + if [ $time -ge $max_seconds ]; then + echo "Maximum number of seconds ($max_seconds) reached." + exit + fi sleep 0.1 done }