warbo-utilities: 359ec1fe8ad820d3007a828fa24b701afc40a7de
1: #!/usr/bin/env bash
2:
3: # Taken from https://www.commandlinefu.com/commands/view/7938/countdown-clock
4:
5: function usage() {
6: echo "Usage: countdown seconds <minutes> <hours>"
7: echo "Counts down the given seconds + minutes + hours then exits"
8: echo "For example, 3 hours 100 minutes would be 'countdown 0 100 3'"
9: }
10:
11: function numeric() {
12: tr -dc '0123456789.'
13: }
14:
15: SECS=$(echo "$1" | numeric)
16: MINS=$(echo "$2" | numeric)
17: HOURS=$(echo "$3" | numeric)
18:
19: [[ -n "$HOURS" ]] || HOURS=0
20: [[ -n "$MINS" ]] || MINS=0
21: [[ -n "$SECS" ]] || {
22: usage 1>&2
23: exit 1
24: }
25:
26: MINS=$(( MINS + (HOURS * 60) ))
27: SECS=$(( SECS + (MINS * 60) ))
28: echo "Sleeping for $SECS seconds (total)" 1>&2
29: for (( i="$SECS"; i>=0; i-- ))
30: do
31: echo -ne "\\r$(date -d"0+$i sec" +%H:%M:%S)"
32: sleep 1
33: done
34: echo
Generated by git2html.