Created
March 23, 2015 21:28
-
-
Save alevy/f00e650948159e87c7da to your computer and use it in GitHub Desktop.
Pomodoro for xmobar with libnotify notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pomodoro_file=$HOME/.pomodoro | |
default_pomodoro_time=1500 | |
pomodoro_time=$default_pomodoro_time | |
default_rest_time=300 | |
rest_time=$default_rest_time | |
notify_cmd="notify-send --icon=$HOME/local/share/icons/pomodoro.png Pomodoro" | |
cmd=$1 | |
start_rest() { | |
local modt=$(stat -c %Y $pomodoro_file) | |
local now=$(date +%s) | |
local end_rest=$(expr $modt + $rest_time) | |
while [ -f $pomodoro_file -a $(stat -c %Y $pomodoro_file) -eq $modt -a $now -lt $end_rest ] | |
do | |
local left=$(expr $end_rest - $now) | |
echo -e "Break for `date -d @$left +%M:%S`" | |
sleep 1 | |
now=$(date +%s) | |
done | |
if [ -e $pomodoro_file -a $(stat -c %Y $pomodoro_file) -eq $modt ] | |
then | |
$notify_cmd "Break is over. Get back to work for 25 minutes!" | |
start_wait "pomodoro" | |
else | |
start_wait | |
fi | |
} | |
start_pomodoro() { | |
local modt=$(stat -c %Y $pomodoro_file) | |
local diff=`expr $(date +%s) - $modt` | |
local left=$(expr $pomodoro_time - $diff) | |
while [ -f $pomodoro_file -a $(stat -c %Y $pomodoro_file) -eq $modt -a $left -gt 0 ] | |
do | |
diff=`expr $(date +%s) - $modt` | |
left=$(expr $pomodoro_time - $diff) | |
local i=$(expr $diff / 60) | |
local rest=$(expr $left / 60) | |
echo -en "[" | |
while [ $i -gt 0 ] | |
do | |
echo -n "#" | |
i=$(expr $i - 1) | |
done | |
while [ $rest -gt 0 ] | |
do | |
echo -n "-" | |
rest=$(expr $rest - 1) | |
done | |
echo "] `date -d @$left +%M:%S`" | |
sleep 1 | |
done | |
if [ -e $pomodoro_file -a $(stat -c %Y $pomodoro_file) -eq $modt ] | |
then | |
$notify_cmd "Take a 5 minute break" | |
start_wait "rest" | |
else | |
start_wait | |
fi | |
} | |
start_wait() { | |
if [ $# -gt 0 -a -e $pomodoro_file ] | |
then | |
case $1 in | |
"pomodoro") | |
echo "pomodoro $pomodoro_time" > $pomodoro_file | |
;; | |
"rest") | |
echo "rest $rest_time" > $pomodoro_file | |
esac | |
fi | |
while [ ! -e $pomodoro_file ] | |
do | |
echo "Pomodoro Off" | |
sleep 1 | |
done | |
IFS=" " | |
read cmd t < $pomodoro_file | |
case $cmd in | |
"pomodoro") | |
pomodoro_time=$t | |
start_pomodoro | |
;; | |
"rest") | |
rest_time=$t | |
start_rest | |
;; | |
esac | |
} | |
case $cmd in | |
"restart") | |
rm -f $pomodoro_file | |
echo "pomodoro" > $pomodoro_file | |
;; | |
"start") | |
rm -f $pomodoro_file | |
pomodoro_time=${2:-$default_pomodoro_time} | |
echo "pomodoro $pomodoro_time" > $pomodoro_file | |
;; | |
"rest") | |
rm -f $pomodoro_file | |
rest_time=${2:-$default_rest_time} | |
echo "rest $rest_time" > $pomodoro_file | |
;; | |
"stop") | |
rm -f $pomodoro_file | |
;; | |
*) | |
start_wait | |
;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment