-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpomodbell
executable file
·122 lines (113 loc) · 3.79 KB
/
xpomodbell
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
#!/bin/sh
#
# xpomodbell - X11 audio bell for Lucas de Sena's pomod Pomodoro timer
#
# CHANGE LOG:
#
# v0.1 - 2024-12-20 - Morgan Aldridge <morgant@makkintosshu.com>
# Initial version.
# v0.2 - 2024-12-25 - Added built-in help, plus arguments for setting
# bell volume level, pomodoro and short/long break
# durations.
#
# LICENSE:
#
# Copyright (c) 2024-2025 Morgan Aldridge
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
DISPLAY="${DISPLAY:-:0}"
SOUND_PATH="${SOUND_PATH:-sounds/}"
_verbose=false
_volume="100"
_pomodoro_length=25
_shortbreak_length=5
_longbreak_length=30
_usage() {
printf "Usage: %s [-v] [-V volume] [-p minutes] [-b minutes] [-B minutes]\n\n" "$(basename "$0")"
printf "Options:\n"
printf "\t-b <minutes> Set short break duration in minutes (default: 5)\n"
printf "\t-B <minutes> Set long break duartion in minutes (default:30)\n"
printf "\t-h Print help (this message) and exit\n"
printf "\t-p <minutes> Set pomodoro duration in minutes (default:25)\n"
printf "\t-v Enable verbose output\n"
printf "\t-V <volume> Set bell sound volume (0-100; default: 100)\n"
}
_is_pomod_running() {
pgrep -qu "$USER" pomod
}
_mpv_play_sound_async() {
$_verbose && printf "\tPlaying sound '%s' asynchronously (volume: %i)...\n" "$1" "$_volume"
export DISPLAY="$DISPLAY"
mpv \
--no-config \
--no-terminal \
--no-video \
--no-resume-playback \
--volume="$_volume" \
"${SOUND_PATH}${1}" &
}
_pomod_launch() {
$_verbose && printf "Starting pomod server and monitoring cycle event notifications...\n"
pomod -p "$_pomodoro_length" -s "$_shortbreak_length" -l "$_longbreak_length" | while read -r _line ; do
case "$_line" in
pomodoro)
$_verbose && printf "\tStarting focus cycle ('%s'; %i minutes)...\n" "$_line" "$_pomodoro_length"
_mpv_play_sound_async "367128__milivolt__keisu-temple-bell.wav"
;;
shortbreak|longbreak)
$_verbose && printf "\tStarting break cycle ('%s')...\n" "$_line"
_mpv_play_sound_async "668647__tec_studio__temple_bell_002.wav"
;;
*)
$_verbose && printf "\tUnknown cycle '%s'!\n" "$_line"
;;
esac
done
$_verbose && printf "pomod server has stopped.\n"
}
# parse arguments
while getopts hvV:p:b:B: _arg ; do
case "$_arg" in
h)
_usage && exit
;;
v)
_verbose=true
;;
V)
_volume="$OPTARG"
;;
p)
_pomodoro_length="$OPTARG"
;;
b)
_shortbreak_length="$OPTARG"
;;
B)
_longbreak_length="$OPTARG"
;;
?|*)
usage && exit 2
;;
esac
done
shift $((OPTIND - 1))
[ $# -gt 0 ] && usage && exit 2
_is_pomod_running && printf "ERROR! pomod is already running! Exiting.\n" && exit 1
_pomod_launch