Skip to content

Instantly share code, notes, and snippets.

@gskielian
Last active August 29, 2015 14:14
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 gskielian/9f73e240678d34f2ec72 to your computer and use it in GitHub Desktop.
Save gskielian/9f73e240678d34f2ec72 to your computer and use it in GitHub Desktop.
pomodoro-like shell script for time management (beeps and does a cowsay to indicate when it's finished)
#!/bin/bash
#check if numeric
is_numeric() {
if [ "$1" -eq "$1" ] 2> /dev/null; then
return 0
else
echo "Error, time input \"$1\" not int, see -h for help" | cowsay -f tux
exit 1
fi
}
#option handling
hours=0
minutes=0
seconds=0
verbose_flag=0
message=""
message_flag=0
while getopts :h:m:s:vr: opt; do
case $opt in
h)
if is_numeric $OPTARG; then
hours=$OPTARG
fi
;;
m)
if is_numeric $OPTARG; then
minutes=$OPTARG
fi
;;
s)
if is_numeric $OPTARG; then
seconds=$OPTARG
fi
;;
v)
verbose_flag=1
;;
r)
message_flag=1
message="$OPTARG"
;;
*) echo "Usage: -h -m -s for hours/min/sec, -v for verbose, -r for reminder, or no parameters for minutes\n"
exit 1
;;
esac
done
shift $((OPTIND-1)) #allows you to use other parameters afterwards as normal
#check if $1 is numeric, if so add to minutes
if [ "$1" -eq "$1" ] 2> /dev/null ; then
minutes=$(($minutes + $1))
elif [ "$1" != "" ]; then
echo "Error, time input \"$1\" not int, see -h for help" | cowsay -f tux
exit 1
fi
if [ $verbose_flag -eq 1 ]; then
echo -e "\n\ntask set to $hours hours, $minutes minutes, and $seconds seconds\n\n"
fi
sleep $(($seconds + $minutes*60 + $hours*3600))
if [ $message_flag -eq 0 ]; then
echo "all done" | figlet | cowsay -n
else
echo "$message" | figlet | cowsay -n
fi
echo -e "\a"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment