giovedì 27 maggio 2010

Pomodoro technique for GNU Screen

The Pomodoro Technique (http://www.pomodorotechnique.com/) is "a way to get the most out of time management" (cit. website).

I've been trying the Pomodoro Technique and various software timers, but none of them satisfied me, mainly because I work using a full-screen shell (Guake: http://guake.org/) and I find distracting to switch to another window to check out the time.

So I wrote a small set of shell scripts that allow me to see the remaining pomodoro time in the lower-right corner of my window, thanks to GNU Screen, a software that I always use to manage virtual screens inside my full-screen terminal (http://www.gnu.org/software/screen/).

Screen allows you to heavily customize the appereance of the virtual screen. I changed mine using bits of code taken around the Internet to display date, time and other info. I exploited this customizability in order to make screen display the residual time of the pomodoro.

Here are the scripts:

start-pomodoro.sh

#!/bin/bash

SECONDS_IN_A_POMODORO=1500 # 25 * 60
ACTUAL_SECONDS=$SECONDS_IN_A_POMODORO
STEP=10
OUTPUT=/tmp/pomodoro

while [[ $ACTUAL_SECONDS > 0 ]]; do
let "will_print = $ACTUAL_SECONDS % $STEP"
if [ $will_print == 0 ]; then
let "minutes = $ACTUAL_SECONDS / 60"
let "seconds = $ACTUAL_SECONDS % 60"
printf "%02d:%02d\n" $minutes $seconds > $OUTPUT
fi
sleep 1
let "ACTUAL_SECONDS = $ACTUAL_SECONDS - 1";
done

stop-pomodoro.sh

#!/bin/bash
killall start-pomodoro.sh
echo stop > /tmp/pomodoro

read-pomodoro.sh

#!/bin/bash
cat /tmp/pomodoro

Now we have to add the command in the GNU Screen configuration file, and to add the output of read-pomodoro.sh in the status line:

.screenrc

backtick 1 5 5 /path/to/read-pomodoro.sh
hardstatus alwayslastline '[ %1` ]'

This is a minimal screen config file, that just displays the remaining time of the pomodoro. You must replace "/path/to/read-pomodoro.sh" with the real path of the script.

Now you can start your pomodoro with start-pomodoro.sh, and enjoy your pomodoro ticking in GNU Screen. With stop-pomodoro.sh you will stop it. In order to restart, run again start-pomodoro.sh.

Note that start-pomodoro.sh is blocking, so you might need to start it in background (start-pomodoro.sh &).

I hope that you find it useful as I did!