From faba6af2eb28611b30f59ab4065c6ff8afbe5d20 Mon Sep 17 00:00:00 2001 From: hazardchem Date: Wed, 23 Nov 2022 22:38:43 +1000 Subject: [PATCH] sxmo_timer.sh: added stopwatch function Added selection for stopwatch in timer Signed-off-by: hazardchem Signed-off-by: Stacy Harper --- scripts/appscripts/sxmo_timer.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/scripts/appscripts/sxmo_timer.sh b/scripts/appscripts/sxmo_timer.sh index a785c89..25a1108 100755 --- a/scripts/appscripts/sxmo_timer.sh +++ b/scripts/appscripts/sxmo_timer.sh @@ -27,9 +27,19 @@ timerrun() { done } +stopwatchrun() { + start="$(date +%s)" + while true; do + time="$(($(date +%s) - start))" + printf '%s\r' "$(date -u -d "@$time" +%H:%M:%S)" + done + sleep 0.1 +} + menu() { TIMEINPUT="$( echo " + Stopwatch 1h 10m 9m @@ -45,8 +55,15 @@ menu() { Close Menu " | awk 'NF' | awk '{$1=$1};1' | sxmo_dmenu_with_kb.sh -p Timer )" || exit 0 - [ "Close Menu" = "$TIMEINPUT" ] && exit 0 - sxmo_terminal.sh "$0" timerrun "$TIMEINPUT" + case "$TIMEINPUT" in + "Close Menu") exit 0 ;; + "Stopwatch") + sxmo_terminal.sh "$0" stopwatchrun + ;; + *) + sxmo_terminal.sh "$0" timerrun "$TIMEINPUT" + ;; + esac } if [ $# -gt 0 ]; then "$@"; else menu; fi