Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 133 lines (114 sloc) 2.899 kb
e5089a3 @tobym version 1
authored
1 #!/bin/bash
2
3 #
4 # NAME
5 # pom -- a minimalist pomodoro-style time-tracker.
6 #
7 # SYNOPSIS
8 # pom message [-l [logfile]]
9 #
10 # DESCRIPTION
6d58339 @tobym Update help to reflect new running time
authored
11 # The pom utility counts down for 25 minutes as you work on a task. It will
d4fc5db @tobym Update help text to mention espeak support
authored
12 # give an audible alert at 5 and 0 minutes if `say` or `espeak` is in the
13 # path and executable.
e5089a3 @tobym version 1
authored
14 #
15 # -l [logfile]
a70a7c2 @tobym Improve documentation
authored
16 # If provided, log the completed task and timestamp to [logfile]. The
17 # default is the POMLOG environment variable, if set. Otherwise, the
e5089a3 @tobym version 1
authored
18 # default is $HOME/pom.log.
19 #
20 # by @tobym (Toby Matejovsky) 2012-09-19.
21
22 # Runtime of a single session.
5389cd2 @tobym Update session running time to pomodoro default, 25 minutes
authored
23 time_in_minutes=25
e5089a3 @tobym version 1
authored
24
25 # Print current status.
26 # First argument is number of minutes elapsed.
27 function print_status {
28 clear
29 minutes_remaining=$(($time_in_minutes - $1))
30 log_line=$(test -n "$logfile" && echo -n " ($logfile)" || echo -n "")
31 echo "Pomodoro$log_line: $minutes_remaining minutes remaining to complete: $goal"
32
33 if [ $minutes_remaining = 5 ]
34 then
6d8ab4d @kgaughan Spin the process announcing 'x minutes remaining' into its own proces…
kgaughan authored
35 safe_say "$minutes_remaining minutes remaining in your pomadoro" &
e5089a3 @tobym version 1
authored
36 fi
37 }
38
39 # Print final status. Optionally log this event.
40 function finish {
41 clear
42 msg="$time_in_minutes minute pomodoro done at $(date) for: $goal"
43 echo $msg
44
45 if [ ! -z $logfile ]
46 then
47 echo $msg >> $logfile
48 fi
49
7b0b2ce @kgaughan Fix typo.
kgaughan authored
50 break_msg="Pomodoro complete. Take a 5 minute break."
e5089a3 @tobym version 1
authored
51 echo $break_msg
52 safe_say "$break_msg" || ring_bell
53 }
54
55 # Audibly say something, if possible.
56 function safe_say {
5065c17 @kgaughan Use espeak on platforms other than MacOS.
kgaughan authored
57 for cmd in espeak say
58 do
ab25502 @kgaughan Ensure the bell can be triggered if no speech software is found.
kgaughan authored
59 which $cmd >/dev/null && $cmd "$1" 2>/dev/null && return
5065c17 @kgaughan Use espeak on platforms other than MacOS.
kgaughan authored
60 done
ab25502 @kgaughan Ensure the bell can be triggered if no speech software is found.
kgaughan authored
61 return 1
e5089a3 @tobym version 1
authored
62 }
63
64 # Try to ring the terminal bell.
65 function ring_bell {
2b7fe89 @kgaughan Play nice with GNU tput when using 'which'.
kgaughan authored
66 which tput >/dev/null && tput bel
e5089a3 @tobym version 1
authored
67 }
68
a70a7c2 @tobym Improve documentation
authored
69 # Print short version of help.
70 function print_usage {
71 echo "Usage: $0 message [-l [logfile]]"
72 }
73
e5089a3 @tobym version 1
authored
74 # Print help.
75 function print_help {
a70a7c2 @tobym Improve documentation
authored
76 help_text='
77 NAME
78 pom -- a minimalist pomodoro-style time-tracker.
79
80 SYNOPSIS
81 pom message [-l [logfile]]
82
83 DESCRIPTION
6d58339 @tobym Update help to reflect new running time
authored
84 The pom utility counts down for 25 minutes as you work on a task. It will
d4fc5db @tobym Update help text to mention espeak support
authored
85 give an audible alert at 5 and 0 minutes if `say` or `espeak` is in the
86 path and executable.
a70a7c2 @tobym Improve documentation
authored
87
88 -l [logfile]
89 If provided, log the completed task and timestamp to [logfile]. The
90 default is the POMLOG environment variable, if set. Otherwise, the
91 default is $HOME/pom.log.
92 '
93
94 echo "$help_text"
e5089a3 @tobym version 1
authored
95 }
96
97 # Main function.
98 function run_main {
99 for minute in `seq $time_in_minutes`
100 do
101 print_status $(($minute-1))
102 sleep 60
103 done
104 finish
105 }
106
107 # Parse options, and run main.
108 goal=$1
109 should_log=$2
110 logfile=$3
111 if [ "$should_log" = "-l" ] && [ -z "$logfile" ]
112 then
113 if [ -z $POMLOG ]
114 then
115 logfile=$HOME/pom.log
116 else
117 logfile=$POMLOG
118 fi
119 fi
120
121 if [ "$1" = "-h" ] || [ "$1" = "--help" ]
122 then
123 print_help && exit 0
124 elif [ -z "$1" ]
125 then
a70a7c2 @tobym Improve documentation
authored
126 print_usage && exit 1
e5089a3 @tobym version 1
authored
127 elif [ ! -z "$2" ] && [ "$2" != "-l" ]
128 then
a70a7c2 @tobym Improve documentation
authored
129 print_usage && exit 1
e5089a3 @tobym version 1
authored
130 else
131 run_main
132 fi
Something went wrong with that request. Please try again.