#!/bin/bash ############################################################ # Argument parsing ############################################################ # We need TEMP as the 'eval set --' would nuke the return value of getopt. TEMP=$(getopt -o 'm:hr:' --long 'message:,help,repetition:' -n 'timer' -- "$@") if [ $? -ne 0 ]; then echo 'Terminating...' >&2 exit 1 fi # Note the quotes around "$TEMP": they are essential! eval set -- "$TEMP" unset TEMP message='' repetition='60' while :; do case "$1" in '-m'|'--message') message="$2"; shift 2; continue;; '-r'|'--repetition') repetition="$2"; shift 2; continue;; '-h'|'--help') cat <&2; exit 1 ;; esac done time="$1" shift if [[ "$message" = "" ]]; then message="Timer \"$time\" is over."; fi ############################################################ # Main code ############################################################ sleep=sleep if type -p fancy-sleep >/dev/null; then sleep=fancy-sleep; fi "$sleep" "$time" || exit 0 while :; do printf "\a" if test "$#" -gt 0; then "$@" else notify-send "$message" spd-say-en "$message" fi "$sleep" "$repetition" || break done