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
|
#!/bin/bash
#
# waybar-breaktimer.sh - modulo custom Waybar per breaktimer
# Legge il tempo rimanente gia' congelato dal daemon (no calcolo next-now).
#
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, see <https://www.gnu.org/licenses/>.
RUNTIME="${XDG_RUNTIME_DIR:-/tmp}"
PID_FILE="$RUNTIME/breaktimer.pid"
STATE_FILE="$RUNTIME/breaktimer.state"
PHASE_FILE="$RUNTIME/breaktimer.phase"
REMAIN_FILE="$RUNTIME/breaktimer.remain"
is_running() {
[ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE" 2>/dev/null)" 2>/dev/null
}
if ! is_running; then
printf '{"text":"","tooltip":"breaktimer: fermo (click dx per avviare)","class":"stopped"}\n'
exit 0
fi
state="$(cat "$STATE_FILE" 2>/dev/null)"
phase="$(cat "$PHASE_FILE" 2>/dev/null)"
rem="$(cat "$REMAIN_FILE" 2>/dev/null)"
[ -z "$rem" ] && rem=0
[ "$rem" -lt 0 ] && rem=0
countdown=$(printf '%d:%02d' $(( rem / 60 )) $(( rem % 60 )))
if [ "$state" = "paused" ]; then
printf '{"text":" %s","tooltip":"breaktimer in pausa (click sx per riprendere)","class":"paused"}\n' "$countdown"
exit 0
fi
case "$phase" in
working)
printf '{"text":" %s","tooltip":"lavoro: pausa tra %s (sx: pausa, dx: stop/restart)","class":"working"}\n' "$countdown" "$countdown"
;;
breaking)
printf '{"text":" %s","tooltip":"micro-pausa: muoviti! ripresa tra %s","class":"breaking"}\n' "$countdown" "$countdown"
;;
longbreak)
printf '{"text":" %s","tooltip":"pausa lunga: stacca! ripresa tra %s","class":"longbreak"}\n' "$countdown" "$countdown"
;;
*)
printf '{"text":" %s","tooltip":"breaktimer attivo","class":"working"}\n' "$countdown"
;;
esac
|