Skip to content

Instantly share code, notes, and snippets.

@madis
Created November 17, 2020 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madis/ff2858f5638d44e4d55799a909f1faeb to your computer and use it in GitHub Desktop.
Save madis/ff2858f5638d44e4d55799a909f1faeb to your computer and use it in GitHub Desktop.
#!/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