-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbreaktime
executable file
·60 lines (53 loc) · 1.2 KB
/
breaktime
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
#!/bin/bash
function printHelp {
echo "$NAME $VERSION"
echo "usage: breaktime [amount timeunit]"
echo "example: breaktime 45 minutes"
echo "NOTE: In absence of defined time, \nbreaktime will default to 45 minutes"
}
function lockScreen {
say -v Daniel "5 seconds to break time"
sleep 5
"/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession" -suspend
}
function getEndTime {
echo $(($(date +%s) + $1))
}
function startTimer {
echo "I will lock your screen when the timer runs out"
echo "-----------------------------------------------"
END=$(getEndTime $1)
while [ $(date +%s) -le $END ]
do
REMAINING=$(($END - $(date +%s)))
MINUTES=$(($REMAINING/60))
SECONDS=$(($REMAINING%60))
echo -en "$MINUTES:$SECONDS to go"
sleep 1
echo -en "\r\033[K"
done
lockScreen
}
if [[ "$@" == "--help" ]]
then
printHelp
exit 0
fi
clear
MULT=1
TIME=$((45 * 60)) # 45 minutes
if [ $# -eq 2 ]
then
if [[ "$2" == "minutes" ]]
then
MULT=60
elif [[ "$2" == "hours" ]]
then
MULT=3600
fi
fi
if [ $# -ge 1 ]
then
TIME=$1
fi
startTimer $(( $TIME * $MULT))