Added user interaction, better filename

This commit is contained in:
Yann Esposito (Yogsototh) 2011-11-14 12:49:09 +01:00
parent a055db70f4
commit fae0e5d5da

View file

@ -8,33 +8,56 @@
# Each work session require you enter a name.
# At the end of the day, all your tasks are keep into ~/Documents/Podomoro
PODOMORO_NO_LOGS=0
# in minutes
WORKING_TIME=25
SHORT_RELAX_TIME=5
LONG_RELAX_TIME=30
PODOMORO_WORKING_TIME=25
PODOMORO_SHORT_RELAX_TIME=5
PODOMORO_LONG_RELAX_TIME=30
function notify() {
local DELAY=5 # in seconds
local ICON=/usr/share/icons/Tango/32x32/actions/appointment.png
print -n -- "$*"
if [[ "$PODOMORO_NOTIFY" != "" ]]; then
eval $( echo $PODOMORO_NOTIFY | sed 's/%m/"'$message'"/g' )
return
fi
case $(uname) in
Darwin) # On Mac
growlnotify -m "Pomodory says $*"
if [[ ! -x =growlnotify ]]; then
{
print -- "Growl seems not installed"
print -- "If you want to have notifications you might want to install it"
} >&2
else
growlnotify -m "Pomodory says $*"
fi
;;
Linux) # on Ubuntu => sudo apt-get install libnotify-bin
# on other systems libnotify
local DELAY=5 # in seconds
local ICON=/usr/share/icons/Tango/32x32/actions/appointment.png
notify-send \
--urgency=critical \
--expire-time=$(( DELAY * 1000 )) \
--icon=$ICON "Pomodoro says" $*
;;
*) {
print -- "I don't made a notification system for your system"
print -- "You can use the \$HOME/.podomoro file to declare your own notification system"
print -- "For example: "
print -- "PODOMORO_NOTIFY=\"notify_cmd --message=%m\""
print
print -- "Then it will be executed as \"notify_cmd\" --message=\"notification message\""
} >&2
esac
}
# show timer
function timer() {
m=$1
s=00
local m=$1
local s=00
local rem="\b\b\b\b\b"
while (( m+s > 0 )); do
((s--))
if ((s<0)); then
@ -42,56 +65,84 @@ function timer() {
((m--))
fi
printf "$rem%02d:%02d" $m $s
rem="\b\b\b\b\b"
sleep 1
read -t 1 && {
print
return 1
}
done
print
return 0
}
funtion posttimer() {
local m=00
local s=00
local rem="\b\b\b\b\b\b"
while : ; do
((s++))
if ((s>59)); then
((s=0))
((m++))
notify "\nTime for a break\n"
fi
printf "$rem+%02d:%02d" $m $s
read -t 1 && break
done
}
# Where to keep trak of your documents?
[[ -e $HOME/.podomoro ]] && source $HOME/.podomoro
if ((NO_LOGS)); then
logfile=/dev/null
else
logfiledir=$HOME/Documents/Podomoro
logfilename=$(date +"tasks-%Y-%m-%d.txt")
logfile=$logfiledir/$logfilename
while [[ ! -d $logfiledir ]]; do
print -- "$logfiledir does not exists. Would you want to create it? (Y/N)"
read answer
case $answer in
Y|YES|y|yes) mkdir -p $logfiledir || exit 1;;
*) print -- "Enter a full path of directory to write logs or just enter NO to don't keep tasks."
function initialize() {
# read the .podomoro file if it exists
[[ -e $HOME/.podomoro ]] && source $HOME/.podomoro
if ((PODOMORO_NO_LOGS)); then
logfile=/dev/null
else
logfiledir=$HOME/Documents/Podomoro
logfilename=$(date +"week-%V.txt")
logfile=$logfiledir/$logfilename
while [[ ! -d $logfiledir ]]; do
print -- "$logfiledir does not exists. Would you want to create it? (y/n)"
read answer
case $answer in
N|n|NO|no) logfiledir=/dev; logfile=/dev/null;;
*)
logfiledir=$answer;
NO_LOGS=1;
logfile=$logfiledir/$logfilename ;;
case $answer in
Y|YES|y|yes) mkdir -p $logfiledir || exit 1;;
*) print -- "Enter a full path of directory to write logs or just enter NO to don't keep tasks."
read answer
case $answer in
N|n|NO|no) logfiledir=/dev; logfile=/dev/null
;;
*) logfiledir=$answer;
NO_LOGS=1;
logfile=$logfiledir/$logfilename ;;
esac
{
print -- "logfiledir=$logfiledir"
(( NO_LOGS )) && print -- "NO_LOGS=1"
} > $HOME/.podomoro
;;
esac
{
print -- "logfiledir=$logfiledir"
(( NO_LOGS )) && print -- "NO_LOGS=1"
} > $HOME/.podomoro
;;
esac
done
fi
done
fi
}
nb=1
initialize
while (true) {
notify "Enter the task"
print -- "Title of the task: "
notify "Enter the title of the task: "
read task
print "$(date +"%H:%M: ") $task" >> $logfile
startedTime=$(date +"%H:%M")
# print "$(date +"%A (%F) %H:%M → ") $task" >> $logfile
print -n -- "WORK NOW! "
timer $WORKING_TIME
print -n "\nTime for a break."
notify "Time for a break."
if ((nb++ % 4 == 0)); then
RELAX_TIME=$LONG_RELAX_TIME
else
RELAX_TIME=$SHORT_RELAX_TIME
if timer $PODOMORO_WORKING_TIME; then
notify "Time for a break."
posttimer
fi
timer $RELAX_TIME
print "$(date +"%A (%F) $startedTime → %H:%M") $task" >> $logfile
if ((nb++ % 4 == 0)); then
PODOMORO_RELAX_TIME=$PODOMORO_LONG_RELAX_TIME
else
PODOMORO_RELAX_TIME=$PODOMORO_SHORT_RELAX_TIME
fi
notify "PAUSE "
timer $PODOMORO_RELAX_TIME
}