-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpomo
executable file
·72 lines (52 loc) · 1.86 KB
/
pomo
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
#!/bin/python
# Make pomo script more sane
# todo: run in bg?
# todo: say time starting and ending
import re
from time import sleep
from sys import argv
from os import system as sh
timer_cmd="mpv --force-window --loop-playlist=inf --really-quiet ~/.scripts/input/ringtone.webm && dunstctl close-all"
def is_pomo (time):
return time == 25 * 60
def pomo_or_timer (b):
return "Pomodoro" if b else "Timer"
def notify_done (time):
sh("notify-send '" + pomo_or_timer(time) + " done!' &")
def set_timer (time, msg):
print(msg if msg else "\0")
if is_pomo(time):
sh("pkill dunst")
sleep(time)
sh("dunst & disown")
else:
sleep(time)
notify_done(time)
sh(timer_cmd)
def parse_time (arg):
regex = r"(\d+)([smh])([eior]?[cnu]?[sr]?[s]?)?(.*)?" #jank
try: # fixme: this still matches 20j20s, somehow
match = re.search (regex, arg)
if match:
num = int(match.group(1))
suffix = match.group(2)
result = num if (suffix == 's') \
else 60 * num if suffix == 'm' \
else 60 * 60 * num
rest = match.group(4)
return result if not rest else result + parse_time (rest)
else:
return 60 * int(arg) # it's just a number, interpret that
# as minutes
except:
# invalid time
return None
def parse_arguments ():
arg1 = parse_time(argv[1]) if len(argv) > 1 else None
# if the first argument is a time, don't include it in the label
label = " ".join([argv[i] for i in range ((2 if arg1 else 1), len(argv))])
time = arg1 if arg1 else 25 * 60
msg = pomo_or_timer(is_pomo(time)) + " set" + (": " + label if label else "")
return [time, msg]
[time, msg] = parse_arguments()
set_timer(time, msg)