Last active
June 24, 2019 14:52
-
-
Save DasNaCl/6a14421f61ac5c9d5ff98d727e65de4a to your computer and use it in GitHub Desktop.
Aids in the use of the Pomodoro-Learning-Technique
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
#!/usr/bin/env bash | |
if [ -z $1 ]; then | |
echo "Expected total number of pomodoro sessions. Use \"?\" or \"h\" if you don\'t know about pomodoro." | |
exit 0 | |
fi | |
if [ "$1" = "h" ] || [ "$1" = "help" ] || [ "$1" = "?" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then | |
echo "The task-completion technique consists of 6 steps:" | |
echo -e " 1) Decide on the task to be done.\n" | |
echo -e " 2) Set the pomodoro timer (traditionally 25 minutes)." | |
echo -e " 3) Work on the task." | |
echo -e " 4) End work when the timer rings and put a checkmark on a piece of paper." | |
echo -e " 5) If you have fewer than 4 checkmarks, take a short break (3-5 minutes),\n then go to step 2." | |
echo -e " 6) After four pomodoros, take a longer break (15-30 minutes), reset your\n checkmark count to zero, then go to step 1." | |
echo -e "\n" | |
echo -e "This tool helps with that, however, the parallel use of non-technical\ntools is encouraged." | |
exit 0 | |
fi | |
[ -n "$1" ] && [ "$1" -eq "$1" ] 2>/dev/null | |
if [ $? -ne 0 ]; then | |
echo "Provided argument is not a number." | |
exit 0 | |
fi | |
break_seconds=0 | |
total_pomodoros="$1" | |
current_pomodoro=0 | |
pomodoros=() | |
while [ $current_pomodoro -ne $total_pomodoros ]; do | |
pomodoros[$current_pomodoro]=0 | |
(( current_pomodoro++ )) | |
done | |
current_pomodoro=0 | |
CHECK_MARK="\033[0;32m\xE2\x9C\x94\033[0m" | |
BATCH_SIZE=4 | |
function update_pomodoros | |
{ | |
tput cud1 | |
echo -ne "\e[0K\r" | |
index=0 | |
for el in "${pomodoros[@]}"; do | |
if [ $el -eq 0 ]; then | |
echo -ne " ☐ " | |
else | |
echo -ne " $CHECK_MARK " | |
fi | |
((index++)) | |
if [ $index -gt 0 ] && [ $(( index % BATCH_SIZE )) -eq 0 ]; then | |
tput cud1 | |
fi | |
done | |
index=0 | |
echo -ne "\e[K" | |
tput cuu1 | |
for i in "${pomodoros[@]}"; do | |
((index++)) | |
if [ $index -gt 0 ] && [ $(( index % BATCH_SIZE )) -eq 0 ]; then | |
tput cuu1 | |
fi | |
done | |
} | |
function clear_pomodoros | |
{ | |
tput cud1 | |
echo -ne "\e[0K\r" | |
index=0 | |
for el in "${pomodoros[@]}"; do | |
echo -ne "\e[0K\r\e[K" | |
((index++)) | |
if [ $index -gt 0 ] && [ $(( index % BATCH_SIZE )) -eq 0 ]; then | |
tput cud1 | |
fi | |
done | |
index=0 | |
echo -ne "\e[K" | |
tput cuu1 | |
for i in "${pomodoros[@]}"; do | |
((index++)) | |
if [ $index -gt 0 ] && [ $(( index % BATCH_SIZE )) -eq 0 ]; then | |
tput cuu1 | |
fi | |
done | |
} | |
function take_break | |
{ | |
break_minutes=5 | |
((tmp=current_pomodoro % BATCH_SIZE)) | |
if [ $tmp -eq 0 ] && [ $current_pomodoro -gt 0 ]; then | |
break_minutes=25 | |
fi | |
BREAK_DURATION_BEGIN=$SECONDS | |
echo -ne "\e[0K\r\e[K" | |
read -n 1 -s -r -p "You now have a $break_minutes minutes break. Press any key to continue." | |
BREAK_DURATION_END=$SECONDS | |
echo -ne "\e[0K\rYour break took $(( (BREAK_DURATION_END - BREAK_DURATION_BEGIN) / 60 )) minutes and $(( (BREAK_DURATION_END - BREAK_DURATION_BEGIN) % 60 )) seconds.\e[K" | |
(( break_seconds += (BREAK_DURATION_END - BREAK_DURATION_BEGIN) )) | |
sleep 1s | |
} | |
function start_session | |
{ | |
for i in {3,2,1}; do | |
echo -ne "\e[0K\r~~ Starting POMODORO-Session in $i... ~~\e[K" | |
sleep 1s | |
done | |
echo -ne "\e[0K\rYou now have 25 minutes to complete your task.\e[K" | |
sleep 2s | |
echo -ne "\e[0K\rYou have ~25 minutes to complete your task.\e[K" | |
sleep 58s | |
sleep 4m | |
echo -ne "\e[0K\rYou have 20 minutes to complete your task.\e[K" | |
sleep 10m | |
echo -ne "\e[0K\rYou have 10 minutes to complete your task.\e[K" | |
sleep 5m | |
echo -ne "\e[0K\rYou have 5 minutes to complete your task.\e[K" | |
sleep 4m | |
echo -ne "\e[0K\rYou have 1 minute to complete your task.\e[K" | |
sleep 1m | |
# we are done, slowly take us out of focus | |
notify-send -i face-wink 'RING!RING!' | |
sleep 3s | |
spd-say "BIEP!BIEP!" | |
sleep 2s | |
wmctrl -a pomodoro.sh | |
spd-say "BIEP!BIEP!" | |
sleep 2s | |
wmctrl -a pomodoro.sh | |
spd-say "BIEP!BIEP!" | |
pomodoros[$current_pomodoro]=1 | |
((current_pomodoro++)) | |
} | |
STUDY_DURATION_BEGIN=$SECONDS | |
update_pomodoros | |
while [ $current_pomodoro -ne $total_pomodoros ]; do | |
start_session | |
update_pomodoros | |
if [ $current_pomodoro -ne $total_pomodoros ]; then | |
take_break | |
fi | |
done | |
STUDY_DURATION_END=$SECONDS | |
clear_pomodoros | |
tput cuu1 | |
update_pomodoros | |
echo -ne "\e[0K\r\e[K" | |
sleep 4s | |
study_time=$(( (STUDY_DURATION_END - STUDY_DURATION_BEGIN) - break_seconds )) | |
echo "Your total study time (excluding breaks) was $(( study_time / 60 )) minutes and $(( study_time % 60 )) seconds. You rested $(( break_seconds / 60 )) minutes and $(( break_seconds % 60 )) seconds." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rev #2: fixed bug where a necessary break was omitted