blob: 5b52ebd645d4fb5699b476c5a167d52cf5344f3d (
plain)
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
|
#!/bin/sh
# time in minutes
[ "$SLEEP_TIME" ] || SLEEP_TIME=25
[ "$BREAK_TIME" ] || BREAK_TIME=5
[ "$GIGA_BREAK_TIME" ] || GIGA_BREAK_TIME=20
### FUNCTIONS
notif() {
herbe "_pomo" "$1" &
sleep 1
pkill -SIGUSR1 herbe
}
# Plays ringing sound
# Then wait for user input to start/end the break
player_command() {
printf >&2 ' > '
[ -r "$ringSound" ] || PLAYER=""
case "$PLAYER" in
mpv) mpv --volume=100 --loop --msg-level=all=no --resume-playback=no "$ringSound" 2>/dev/null;;
"") head -n 1 ;;
*) $PLAYER "$ringSound" ;;
esac
}
# $1: time in minutes
# $2: msg for notification
ring_ring() {
printf >&2 '%s %s [%s]\n' "$(date '+%R')" "Break" "$round"
player_command
herbe "pomo" "$2" &
sleep "${1}m"
player_command
printf >&2 '\n'
}
### Program
trap 'exit 1' INT
round="${1:-0}"
# args
case "$round" in
0 | 1 | 2 | 3) ;;
ring) ;;
*) printf >&2 'Invalid value: %s\n' "$round"; exit 1 ;;
esac
ringSound="${XDG_DATA_HOME:-$HOME/.local/share}"/pomo/ring.aac
# For debugging purposes
if [ "$1" = "ring" ]; then
>&2 printf 'PLAYER: %s\n' "$PLAYER "
>&2 printf 'ringSound: %s\n' "$ringSound"
player_command
exit
fi
# Countdown
for msg in "three" "two" "one"; do
notif "$msg"
done
while true; do
notif "*START"
printf >&2 '%s %s [%s]\n' "$(date '+%R')" "Start" "$round"
sleep "${SLEEP_TIME}m"
if [ "$round" -eq 3 ]; then
ring_ring "$GIGA_BREAK_TIME" "*GIGA BREAK TIME"
round=0
else
ring_ring "$BREAK_TIME" "*BREAK TIME"
round=$((round + 1))
fi
done
|