-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer
More file actions
executable file
·55 lines (38 loc) · 922 Bytes
/
timer
File metadata and controls
executable file
·55 lines (38 loc) · 922 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
echo "Warming up..."
SECONDS_RUNNING=0
function floor {
local _dividend=$1
local _divisior=$2
echo $((($_dividend - ($_dividend % $_divisior )) / $_divisior))
}
function to_two_digits {
local _input=$1
printf "%02d\n" $_input
}
function get_hours {
local _seconds=$1
local _hours=$(floor $_seconds 3600)
echo $(to_two_digits $_hours)
}
function get_minutes {
local _seconds=$1
local _minutes=$(floor $_seconds 60)
local _minutes_remaining=$(($_minutes % 60))
echo $(to_two_digits $_minutes_remaining)
}
function get_seconds {
local _seconds=$1
local _minute_seconds=$(($_seconds % 60))
echo $(to_two_digits $_minute_seconds)
}
while (true)
do
sleep 1
((SECONDS_RUNNING++))
_HOURS=$(get_hours $SECONDS_RUNNING)
_MINUTES=$(get_minutes $SECONDS_RUNNING)
_SECONDS=$(get_seconds $SECONDS_RUNNING)
_OUTPUT="Timer: $_HOURS:$_MINUTES:$_SECONDS"
echo -e "\e[1A\e[K$_OUTPUT"
done;