From bce7c562155a927cc82f038da69a15f50a66cbeb Mon Sep 17 00:00:00 2001 From: _N3m0 Date: Wed, 21 Feb 2024 14:42:56 +0100 Subject: [PATCH] add chrono --- chrono | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 chrono diff --git a/chrono b/chrono new file mode 100755 index 0000000..f0f1b38 --- /dev/null +++ b/chrono @@ -0,0 +1,48 @@ +#!/bin/bash + +h=0 +m=0 +s=0 +direction=1 + +function chrono() { + while true; do + echo -en "\r$h:$m:$s " + sleep 1 + + s=$(($s+$direction)) + + if [ $s -ge 60 ]; then + s=0 + m=$(($m+$direction)) + elif [ $s -lt 0 ]; then + s=59 + m=$(($m+$direction)) + fi + + if [ $m -ge 60 ]; then + m=0 + h=$(($h+$direction)) + elif [ $m -lt 0 ]; then + m=59 + h=$(($h+$direction)) + fi + + if [ $s -eq 0 -a $m -eq 0 -a $h -eq 0 ]; then + echo -e "\r$h:$m:$s " + break + fi + done +} + +if [ ! -z $1 ]; then + h=$(echo $1 | cut -d ':' -f1) + m=$(echo $1 | cut -d ':' -f2) + s=$(echo $1 | cut -d ':' -f3) + direction=-1 + chrono +else + chrono & + read + kill %1 +fi