-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pomodororc
executable file
·113 lines (96 loc) · 2.47 KB
/
.pomodororc
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
STORAGE="${HOME}/.pomodoro.d"
SOUND="off"
NOTIFICATION_SOUND=
POMODORO_TIME=45
SHORT_BREAK_TIME=10
LONG_BREAK_TIME=55
CYCLES_BETWEEN_LONG_BREAKS=3
function now() {
date "+%H:%M:%S"
}
function log() {
echo "$(now) $@" >>/tmp/${USER}.pomodoro.log
}
function pause() {
NOTIFICATION_SOUND="${HOME}/res/pause_pomodoro.mp3"
# custom code to run when the pomodoro is paused
"${HOME}/bin/do-not-disturb" disable
}
function resume() {
# custom code to run when the pomodoro is resumed
if [[ "$1" == "pomodoro" ]]; then
NOTIFICATION_SOUND="${HOME}/res/bell_hop.mp3"
"${HOME}/bin/do-not-disturb" enable
fi
}
function shortbreak_start() {
# custom code to run when the pomodoro short break starts
"${HOME}/bin/do-not-disturb" disable
}
function shortbreak_end() {
# custom code to run when the pomodoro short break starts
# "${HOME}/bin/do-not-disturb" enable
echo &>/dev/null # NOOP
}
function longbreak_start() {
# custom code to run when the pomodoro short break starts
"${HOME}/bin/do-not-disturb" disable
}
function longbreak_end() {
# custom code to run when the pomodoro short break starts
# "${HOME}/bin/do-not-disturb" disable
echo &>/dev/null # NOOP
}
function pomodoro_start() {
NOTIFICATION_SOUND="${HOME}/res/start_pomodoro.mp3"
"${HOME}/bin/do-not-disturb" enable
}
function pomodoro_end() {
NOTIFICATION_SOUND="${HOME}/res/pomodoro_done.mp3"
"${HOME}/bin/do-not-disturb" disable
}
function run_command() {
local fn_name="$1"
if type -t "${fn_name}" &>/dev/null; then
"$@"
else
log "No handler for event: ${fn_name}"
fi
# if [[ "${NOTIFICATION_SOUND}" ]]; then
# play -q "${NOTIFICATION_SOUND}" &
# disown $!
# fi
}
function run_pomodoro_raw() {
"${HOME}/modules/pomodoro/pomodoro.sh" "$@"
}
function run_pomodoro() {
run_pomodoro_raw \
--storage "${STORAGE}" \
--sound "${SOUND}" \
--pomodoro_time "${POMODORO_TIME}" \
--short_break_time "${SHORT_BREAK_TIME}" \
--long_break_time "${LONG_BREAK_TIME}" \
--cycles_between_long_breaks "${CYCLES_BETWEEN_LONG_BREAKS}" \
--custom_cmd "${HOME}/.pomodororc"
}
# First time we're trying to run pomodoro or we're re-rendering
if [[ $# -eq 0 ]]; then
run_pomodoro
exit $?
else
case "$1" in
# An event was triggered by pomodoro
--command|-c)
log "Running command: $2"
shift
run_command "$@"
;;
# User clicked on the pomodoro icon
*)
run_pomodoro_raw "$@"
exit $?
;;
esac
fi