blob: 9c399379597ee212fc3c6947cfa9ad13d1502434 (
plain) (
blame)
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
|
#!/bin/bash
#
# gromo - To count your daily gromodoros :thumbsup
#
# Dependencies: curl and mpv for the 'ding' sound; slock to force you to rest :)
################################################################################
DEFAULT_DING=https://gramos.me/ding.opus
GROMO_SECONDS=$((60 * 20))
STOP_SECONDS=20
DATA_DIR=${XDG_DATA_HOME:-$HOME/.local/share}/gromo
TODAY_FILE=$DATA_DIR/$(date -I)
DING_FILE=${XDG_CACHE_HOME:-$HOME/.cache}/gromo/ding.opus
WORKING_FILE=$DATA_DIR/working
mkdir -p "$DATA_DIR"
gromos=0
[ -f "$TODAY_FILE" ] && read -r gromos < "$TODAY_FILE"
if [ "$1" = "--xmobar-status" ]; then
if [ -f "$WORKING_FILE" ]; then
echo "<fc=red>working</fc> ($gromos)"
else
echo "<fc=green>idle</fc> ($gromos)"
fi
exit 0
fi
[ -f "$DING_FILE" ] || curl $DEFAULT_DING --create-dirs -so "$DING_FILE"
trap "rm -f $WORKING_FILE; exit" INT TERM EXIT
rm -f $WORKING_FILE
while true; do
read -rn1 -p "Press any key to start gromo > "
echo -ne "\r\033[K"
touch $WORKING_FILE
sleep $GROMO_SECONDS
rm -f $WORKING_FILE
gromos=$((gromos+1))
seconds=$((gromos * GROMO_SECONDS))
echo "$gromos" > "$TODAY_FILE"
(sleep $STOP_SECONDS && mpv --no-terminal "$DING_FILE") &
slock
if [ $seconds -lt 60 ]; then
gromo_time="$seconds seconds"
elif [ $seconds -lt 3600 ]; then
gromo_time="$((seconds / 60)) minutes"
else
gromo_time="$((seconds / 3600)) hours"
fi
echo -ne "Completed $gromos gromos today ($gromo_time). "
done
|