blob: fe5f4c35bdc35178773cc1ccfe9d600f242b22bc (
plain) (
blame)
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
|
#!/bin/sh
COMMAND=$1
case "$COMMAND"
in
"start")
if [ "$#" -ne 2 ]; then
echo "Usage: listimer start <minutes>";
exit 1;
fi
DURATION_MIN=$2
CURRENT_TIME=$(date +%s)
echo "$CURRENT_TIME\n\n$DURATION_MIN" > /tmp/listimer
;;
"restart")
if [ "$#" -ne 1 ]; then
echo "Usage: listimer restart";
exit 1;
fi
CURRENT_TIME=$(date +%s)
sed -i "1s/.*/$CURRENT_TIME/" /tmp/listimer
;;
"stop")
if [ "$#" -ne 1 ]; then
echo "Usage: listimer stop";
exit 1;
fi
CURRENT_TIME=$(date +%s)
rm /tmp/listimer
;;
"query")
if [ ! -f /tmp/listimer ]; then
echo "No timer"
exit 0;
fi
START_TIME=$(sed -n '1p' < /tmp/listimer)
DURATION_MIN=$(sed -n '3p' < /tmp/listimer)
DURATION_SEC=$DURATION_MIN*60
CURRENT_TIME=$(date +%s)
ELAPSED_TIME_SEC=$(($CURRENT_TIME-$START_TIME))
ELAPSED_TIME_MIN=$(($ELAPSED_TIME_SEC/60))
REMAINING_TIME_MIN=$(($DURATION_MIN-$ELAPSED_TIME_MIN))
if [ "$REMAINING_TIME_MIN" -lt "$(($DURATION_MIN / 2))" ]; then
echo "<span weight=\"bold\" size=\"larger\" background=\"#FF0000\">$REMAINING_TIME_MIN minutes</span>"
elif [ "$REMAINING_TIME_MIN" -lt "0" ]; then
echo "TIME OUT!"
else
echo "$REMAINING_TIME_MIN minutes"
fi
;;
*) echo "Unexpected command."
esac
|