-
Notifications
You must be signed in to change notification settings - Fork 0
/
tomato.sh
executable file
·132 lines (113 loc) · 2.1 KB
/
tomato.sh
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/sh
set -o errexit
set -o nounset
usage() {
cat <<EOF
Usage:
$0 [OPTION]...
Options:
-h, --help Show this message
-w, --work <duration> Duration of a work session (Default 25m)
-b, --break <duration> Duration of a short break (Default 5m)
-c, --cycles <number> Number of cycles (Default 4)
-f, --file <filename> File used for logging the mode changes (Default tempfile)
-n, --notifier <command> Script to use as notifier (Default default_notifier)
Examples:
$0 -w 2m -b 30s -c 6
$0 -n ./example_notifier.sh
$0 -f custom.log
$0 -w 5s -b 3s -c 3 -f custom.log -n ./example_notifier.sh
Notifier:
notify <mode> Called with a mode as arg
Modes:
work Time to work in your task
break Time to take a break and relax
end You reached the end of the session
EOF
}
err() {
echo "Err: "$1
usage
exit 1
}
noise() {
case $1 in
break) song=pink;;
work|end) song=sine;;
esac
(
speaker-test -l 1 -p 1 -t $song &
) 1>/dev/null 2>&1
}
default_notifier() {
notify-send "$@"
which speaker-test 1>/dev/null 2>&1 && noise "$@"
}
log() {
echo $(date +%d-%m-%Y_%H:%M:%S)" $@"
}
while [ $# -gt 0 ] ; do
nSkip=2
case $1 in
"-h"|"--help")
usage
exit 0
;;
"--work"|"-w")
w=$2
;;
"--break"|"-b")
b=$2
;;
"--cycles"|"-c")
c=$2
;;
"--file"|"-f")
f=$2
;;
"--notifier"|"-n")
n=$2
;;
*)
err "invalid option"
;;
esac
shift $nSkip
done
default_w="25m"
default_b="5m"
default_c="4"
default_n=default_notifier
W=${w-$default_w}
B=${b-$default_b}
C=${c-$default_c}
N=${n-$default_n}
case ${f-""} in
"") logFile=$(mktemp --suffix=-tomato)
trap "rm -f $logFile" EXIT ;;
*) logFile=$f ;;
esac
echo "Work: $W"
echo "Break: $B"
echo "Cycles: $C"
echo "Notifier: $N"
echo "Log file: $logFile"
while [ $C -gt 0 ]
do
$N work
log work >> $logFile
sleep $W
C=$(($C - 1))
case $C in
0)
log end >> $logFile
$N end
break
;;
*)
$N break
log break >> $logFile
sleep $B
esac
done
exit 0