-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer
More file actions
113 lines (99 loc) · 1.92 KB
/
timer
File metadata and controls
113 lines (99 loc) · 1.92 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
setup_window () {
min=$(zenity --entry --text "Enter minutes:")
if [ "$min" == "" ]; then
exit
fi
min=$(( $min*60 ))
now=`date +%s`
echo "$(( $min + $now ))"
}
# e.g. 16:50
setup_window_time () {
min=$(zenity --entry --text "Enter exact time:")
if [ "$min" == "" ]; then
exit
fi
# convert
min=`date --date=$min +%s`
echo $min
}
done_window () {
# paplay /usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga
zenity --info --width=500 --height=250 --ellipsize --text "Timer!"
}
fix_digits () {
digit=$1
chrlen=${#digit}
if [ $chrlen -eq 1 ]; then
digit="0"$digit
fi
echo "$digit"
}
print_elapsed () {
ELAPSE=$1 # compute elapsed time in seconds
HOURS=$(( $ELAPSE/60/60 ))
MINS=$(( $ELAPSE/60 - ($HOURS*60) )) # convert to minutes... (dumps remainder from division)
SECS=$(( $ELAPSE - ($MINS*60) - ($HOURS*60*60) )) # ... and seconds
NC='\033[0m' # No Color
if [ $HOURS -gt 0 ]; then
MINS=$( fix_digits $MINS )
SECS=$( fix_digits $SECS )
echo "$HOURS:$MINS:$SECS"
echo "$HOURS:$MINS:$SECS"
elif [ $MINS -gt 0 ]; then
SECS=$( fix_digits $SECS )
echo "$MINS:$SECS"
echo "$MINS:$SECS"
elif [[ condition ]]; then
echo "$SECS"
echo "$SECS"
fi
colorise $ELAPSE
}
colorise () {
min=$1
warn=300
crit=60
warnCol="#FFFF00"
if [ $min -le $crit ]; then
exit 33;
elif [ $min -lt $warn ]; then
echo $warnCol
fi
}
reset () {
echo "0">$zfile
}
# test
if [ "$1" == "test" ]; then
min=$( setup_window_time )
echo $min
echo `date +%s`
fi
zfile=`dirname $0`/zzz
if [ "$BLOCK_BUTTON" == 1 ]; then
min=$( setup_window )
echo $min>$zfile
elif [ "$BLOCK_BUTTON" == 2 ]; then
reset
elif [ "$BLOCK_BUTTON" == 3 ]; then
min=$( setup_window_time )
echo $min>$zfile
fi
if [ ! -f $zfile ]; then
echo
exit
fi
min=`cat $zfile`
now=`date +%s`
if [ $min -gt $now ]; then
print_elapsed $(( $min - $now))
else
if [ $min -eq 0 ]; then
echo
else
reset
done_window
fi
fi