aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/unix/stopwatch.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/unix/stopwatch.sh')
-rwxr-xr-xbin/unix/stopwatch.sh37
1 files changed, 0 insertions, 37 deletions
diff --git a/bin/unix/stopwatch.sh b/bin/unix/stopwatch.sh
deleted file mode 100755
index 6b76c26..0000000
--- a/bin/unix/stopwatch.sh
+++ /dev/null
@@ -1,37 +0,0 @@
1#! /bin/bash
2# Ref: https://superuser.com/questions/611538/611582#611582
3
4# If user type '^C', then use SIGINT to toggle the display
5trap '[ "$SHOWGIVEN" = yes ] && SHOWGIVEN= || SHOWGIVEN=yes' SIGINT
6# Do not print "^C" when SIGINT caught
7stty -ctlecho
8
9# Hide the cursor
10tput civis
11
12# Wait user input
13read -p '? ' input
14
15# Modify input to fit the format that `date` can read
16# s -> sec
17# m -> min
18# h -> hour
19[[ "$input" =~ s && ! "$input" =~ sec ]] && input="$(sed s/s/sec/ <<<"$input")"
20[[ "$input" =~ m && ! "$input" =~ min ]] && input="$(sed s/m/min/ <<<"$input")"
21[[ "$input" =~ h && ! "$input" =~ hour ]] && input="$(sed s/h/hour/ <<<"$input")"
22
23time=0
24start=$(date +%s)
25given=$(date +%s -d "$input")
26stop=$(( $given - $start ))
27while [ $time -ne $stop ]; do
28 time="$(( $(date +%s) - $start ))"
29 if [ -z "$SHOWGIVEN" ]; then
30 printf '%s\r' "$(date -u -d @$time +%H:%M:%S)"
31 else
32 printf '%s\r' "$(date -u -d @$stop +%H:%M:%S)"
33 fi
34 sleep 0.3
35done
36
37printf "\e[1;31m$(date -u -d "@$time" +%H:%M:%S)"