Created
November 17, 2020 10:39
-
-
Save madis/ff2858f5638d44e4d55799a909f1faeb to your computer and use it in GitHub Desktop.
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 | |
function check_arguments() { | |
if [ -z "$1" ] | |
then | |
echo "No argument supplied" | |
echo " Usage : ./track-study.sh <seconds to study>" | |
echo " Example: ./track-study.sh 10" | |
exit | |
fi | |
} | |
function count_down_time() { | |
TOTAL_STUDY_TIME=$1 | |
for SECONDS_STUDIED in $(seq 1 $TOTAL_STUDY_TIME) | |
do | |
PERCENTAGE_DONE=$(($SECONDS_STUDIED*100/$TOTAL_STUDY_TIME)) | |
sleep 1 | |
echo -ne "$SECONDS_STUDIED seconds studied ($PERCENTAGE_DONE %) ...\r" | |
done | |
} | |
function congratulate() { | |
MESSAGE="Congratulations. You can have a break now." | |
echo $MESSAGE | |
# On MacOS there's program `say` which synthesizes speech to speakers | |
if command -v say &> /dev/null | |
then | |
say $MESSAGE | |
fi | |
} | |
# Main part of the program | |
check_arguments $1 | |
count_down_time $1 | |
congratulate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment