diff options
Diffstat (limited to 'bin/unix/countdown.sh')
-rwxr-xr-x | bin/unix/countdown.sh | 34 |
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 | ||
5 | trap '[ "$SHOWGIVEN" = yes ] && SHOWGIVEN= || SHOWGIVEN=yes' SIGINT | ||
6 | # Do not print "^C" when SIGINT caught | ||
7 | stty -ctlecho | ||
8 | |||
9 | # Hide the cursor | ||
10 | tput civis | ||
11 | |||
12 | # Wait user input | ||
13 | read -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 | |||
23 | start=$(date +%s -d "$input") | ||
24 | while [ "$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 | ||
33 | done | ||
34 | printf "\e[1;31m$(date -u -d "@$time" +%H:%M:%S)" | ||