aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/unix/countdown.sh
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2023-02-27 16:04:51 +0800
committerHsieh Chin Fan <pham@topo.tw>2023-02-27 16:04:51 +0800
commitc4377f99fbbb8c95be46b4c6399d1db376688940 (patch)
treeb4bd76f42259fa9a676b294190f7f79d7c2cf03a /bin/unix/countdown.sh
parent005cf5f0fed1d253631e00e228f69d6e3e487771 (diff)
Update timer.sh
Diffstat (limited to 'bin/unix/countdown.sh')
-rwxr-xr-xbin/unix/countdown.sh34
1 files changed, 0 insertions, 34 deletions
diff --git a/bin/unix/countdown.sh b/bin/unix/countdown.sh
deleted file mode 100755
index ca6b5d6..0000000
--- a/bin/unix/countdown.sh
+++ /dev/null
@@ -1,34 +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
23start=$(date +%s -d "$input")
24while [ "$start" -ge $(date +%s) ]; do
25 ## Is this more than 24h away?
26 time="$(( $start - `date +%s` ))"
27 if [ -z "$SHOWGIVEN" ]; then
28 printf '%s\r' "$(date -u -d @$time +%H:%M:%S)"
29 else
30 printf '%s\r' "$(date -d "00 + $input" +%H:%M:%S)"
31 fi
32 sleep 0.3
33done
34printf "\e[1;31m$(date -u -d "@$time" +%H:%M:%S)"