Permalink
Browse files

version 1

  • Loading branch information...
1 parent 289569d commit e5089a33b407d18f0c4d62ce2d14d458ae4316fc @tobym committed Sep 19, 2012
Showing with 105 additions and 0 deletions.
  1. +105 −0 pom
View
105 pom
@@ -0,0 +1,105 @@
+#!/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=20
+
+# 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 help.
+function print_help {
+ echo "Usage: $0 message [-l [logfile]]"
+}
+
+# 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_help && exit 1
+elif [ ! -z "$2" ] && [ "$2" != "-l" ]
+then
+ print_help && exit 1
+else
+ run_main
+fi

0 comments on commit e5089a3

Please sign in to comment.