Created
October 31, 2016 20:28
-
-
Save ichaida/a385d0681f660c1f80023010bdc64e50 to your computer and use it in GitHub Desktop.
Break Time is a simple shell script that's help you remember to take breaks away from your computer.
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
#!/bin/bash | |
# Visit Github: | |
# https://github.com/variadico/noti | |
# Install latest: | |
# go get -u github.com/variadico/noti/cmd/noti | |
# On macOS: | |
# brew install noti | |
usage(){ | |
echo "BreakTime Shell Script." | |
echo | |
echo "Break Time is a simple utility that's help you remember to take breaks away from your computer." | |
echo | |
echo "Usage: $0 break time in minutes" | |
echo | |
echo "Arguments:" | |
echo "-m Short period focus (minutes)" | |
echo "-b Short break (minutes)" | |
echo | |
echo "Example:" | |
echo "$0 -m 20 -b 4 Runs for 20 minutes short period focus and 4 minutes break." | |
echo | |
exit 1 | |
} | |
readonly -f usage | |
# Invoke usage function if arguments were not supplied | |
if [[ $# -eq 0 ]] | |
then | |
usage | |
fi | |
# Must have all arguments | |
if [[ $# -ne 4 ]] | |
then | |
usage | |
fi | |
# Counter, mapping minutes | |
break_count_minutes=0 | |
# Time for short period focus | |
total_breaks_minutes=25 | |
# Break time | |
break_time_minutes=5 | |
# Parsing arguments | |
while [ $# -ge 1 ]; | |
do | |
case "$1" in | |
--) | |
# No more arguments left. | |
shift | |
break | |
;; | |
-m) | |
# Time for short period focus | |
total_breaks_minutes="$2"; | |
shift | |
;; | |
-b) | |
# Break time | |
break_time_minutes="$2"; | |
shift | |
;; | |
-h|--help) | |
usage; | |
exit 0 | |
;; | |
*) | |
# Unknown argument, print usage and exit | |
usage; | |
exit 0 | |
;; | |
esac | |
# Consume argument, pass to the next one | |
shift | |
done | |
# Print variables | |
echo "[ ${total_breaks_minutes} minutes short period focus for ${break_time_minutes} minutes break...]" | |
echo "[ Hit CTRL+C to Stop ]" | |
echo | |
# Infinite loop | |
while true; do | |
if [[ ${break_count_minutes} -eq ${total_breaks_minutes} ]] | |
then | |
# Take a break | |
echo "> Hi, Break Time for ${break_time_minutes} minutes..." | |
/usr/local/bin/noti -t "Break Time" -m "You have to rest" | |
# Reset counter to zero | |
break_count_minutes=0 | |
# Break | |
/bin/sleep $((${break_time_minutes} * 60)) | |
# Return to work | |
echo "> Hey, return to work now." | |
/usr/local/bin/noti -t "Break Time" -m "Return to your code" | |
echo | |
fi | |
/bin/sleep 60 | |
# Track time | |
((break_count_minutes=break_count_minutes+1)) | |
# End loop | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment