-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcountdown
More file actions
executable file
·54 lines (45 loc) · 1.53 KB
/
countdown
File metadata and controls
executable file
·54 lines (45 loc) · 1.53 KB
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
#!/bin/sh
# A countdown timer
# Joe Standring <git@joestandring.com>
# GNU GPLv3
# Pausing notifications
# dunstctl set-paused true
# kill -48 $(pidof dwmblocks)
# Signal 3 + 34 = 37 triggers dwm_countdown block in dwmblocks
SIGNAL=37
# Check for an existing instance
for _f in /tmp/countdown.*; do
if [ -e "$_f" ]; then
printf "There may be another instance of this script running. If you are sure there is not, delete the file %s and try again.\n" "$_f"
exit 1
fi
break
done
TMP=$(mktemp /tmp/countdown.XXXXX)
trap 'rm -f "$TMP"; kill -$SIGNAL $(pidof dwmblocks) 2>/dev/null; trap - EXIT; exit' EXIT INT HUP
# If there are 3 arguments given, they become H, M, and S. Otherwise, the user is asked
if [ $# -eq 3 ]; then
HOU=$1
MIN=$2
SEC=$3
else
read -r -p 'Hours: ' HOU
read -r -p 'Minutes: ' MIN
read -r -p 'Seconds: ' SEC
fi
TIMER=$(( (HOU*3600) + (MIN*60) + SEC ))
while [ $TIMER -gt 0 ]; do
printf "%02dh:%02dm:%02ds\n" $((TIMER/3600)) $((TIMER%3600/60)) $((TIMER%60))
# Overwrite (not append) — file stays 1 line
printf "%02d:%02d:%02d\n" $((TIMER/3600)) $((TIMER%3600/60)) $((TIMER%60)) > "$TMP"
# Signal dwmblocks to refresh the countdown block
kill -$SIGNAL $(pidof dwmblocks) 2>/dev/null
sleep 1
TIMER=$(( TIMER - 1 ))
done
# Timer finished — trap will clean up TMP and signal dwmblocks
dunstctl set-paused false
kill -48 $(pidof dwmblocks) 2>/dev/null
printf "Timer Finished" | dmenu -sb "red" -sf "black"
notify-send "Timer Finished!"
# mpv ~/scripts/alarm.ogg