Skip to content

Instantly share code, notes, and snippets.

@madis
Created Nov 17, 2020
Embed
What would you like to do?
#!/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