-
Notifications
You must be signed in to change notification settings - Fork 0
/
pom
executable file
·128 lines (110 loc) · 2.72 KB
/
pom
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
#
# NAME
# pom -- a minimalist pomodoro-style time-tracker.
#
# SYNOPSIS
# pom message [-l [logfile]]
#
# DESCRIPTION
# The pom utility counts down for 20 minutes as you work on a task. It will
# give an audible alert at 5 and 0 minutes if `say` is in the path and
# executable.
#
# -l [logfile]
# If provided, log the completed task and timestamp to [logfile]. The
# default is the POMLOG environment variable, if set. Otherwise, the
# default is $HOME/pom.log.
#
# by @tobym (Toby Matejovsky) 2012-09-19.
# Runtime of a single session.
time_in_minutes=25
# Print current status.
# First argument is number of minutes elapsed.
function print_status {
clear
minutes_remaining=$(($time_in_minutes - $1))
log_line=$(test -n "$logfile" && echo -n " ($logfile)" || echo -n "")
echo "Pomodoro$log_line: $minutes_remaining minutes remaining to complete: $goal"
if [ $minutes_remaining = 5 ]
then
safe_say "$minutes_remaining minutes remaining in your pomadoro"
fi
}
# Print final status. Optionally log this event.
function finish {
clear
msg="$time_in_minutes minute pomodoro done at $(date) for: $goal"
echo $msg
if [ ! -z $logfile ]
then
echo $msg >> $logfile
fi
break_msg="Pomadoro complete. Take a 5 minute break."
echo $break_msg
safe_say "$break_msg" || ring_bell
}
# Audibly say something, if possible.
function safe_say {
which -s say && say $1
}
# Try to ring the terminal bell.
function ring_bell {
which -s tput && tput bel
}
# Print short version of help.
function print_usage {
echo "Usage: $0 message [-l [logfile]]"
}
# Print help.
function print_help {
help_text='
NAME
pom -- a minimalist pomodoro-style time-tracker.
SYNOPSIS
pom message [-l [logfile]]
DESCRIPTION
The pom utility counts down for 20 minutes as you work on a task. It will
give an audible alert at 5 and 0 minutes if `say` is in the path and
executable.
-l [logfile]
If provided, log the completed task and timestamp to [logfile]. The
default is the POMLOG environment variable, if set. Otherwise, the
default is $HOME/pom.log.
'
echo "$help_text"
}
# Main function.
function run_main {
for minute in `seq $time_in_minutes`
do
print_status $(($minute-1))
sleep 60
done
finish
}
# Parse options, and run main.
goal=$1
should_log=$2
logfile=$3
if [ "$should_log" = "-l" ] && [ -z "$logfile" ]
then
if [ -z $POMLOG ]
then
logfile=$HOME/pom.log
else
logfile=$POMLOG
fi
fi
if [ "$1" = "-h" ] || [ "$1" = "--help" ]
then
print_help && exit 0
elif [ -z "$1" ]
then
print_usage && exit 1
elif [ ! -z "$2" ] && [ "$2" != "-l" ]
then
print_usage && exit 1
else
run_main
fi