summaryrefslogtreecommitdiffstats
path: root/public/.local/bin/sb-stopwatch
blob: 06aa0e6078749886405d55c777e71a052b885cc1 (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
#!/bin/sh

# Custom stopwatch for "timeblocking"

STATE_FILE="/tmp/sb-stopwatch.state"

case $BLOCK_BUTTON in
	1) setsid -w -f "$TERMINAL" -e pulsemixer; pkill -RTMIN+10 "${STATUSBAR:-dwmblocks}" ;;
	2) wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle ;;
	4) wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%+ ;;
	5) wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%- ;;
	3) notify-send "📢 Volume module" "\- Shows volume 🔊, 🔇 if muted.
- Middle click to mute.
- Scroll to change." ;;
	6) "$TERMINAL" -e "$EDITOR" "$0" ;;
esac


read_timer() {
    if [ ! -f "$STATE_FILE" ]; then
        # If no state file, then no counter, exit
        exit 0
    fi

    #if ! [[ "$end_time" =~ ^[0-9]+$ ]]; then
    #    echo "Invalid end_time in the state file."
    #    exit 1
    #fi

    end_time=$(cat "$STATE_FILE")
    current_time=$(date +%s)
    remaining_time=$((end_time - current_time))

    if [ $remaining_time -lt 0 ]; then
        # Time's up!  Beep and exit
        rm $STATE_FILE
        paplay /opt/suckless/sb-stopwatch.wav
        exit 0
    fi

    remaining_minutes=$((remaining_time / 60))
}


read_timer
echo "⏳${remaining_minutes}m"

# Emoji related to stopwatch:
#⏱️ — Stopwatch
#⏳ — Hourglass with flowing sand
#🕰️ — Mantelpiece clock
#🕒 — Clock face showing 3:00
#⏰ — Alarm clock
#🕰️ — Clock face
#⏮️ — Previous track button (for rewind, related to time)