#!/usr/bin/env bash ((hours = minutes = seconds = 0)) while getopts "h:m:s:" flag; do case "${flag}" in h) hours="${OPTARG}" ;;& m) minutes="${OPTARG}" ;;& s) seconds="${OPTARG}" ;;& h | m | s) re='^[0-9]+$' if ! [[ "${OPTARG}" =~ $re ]]; then printf 'Error: flag "-%s" expected an integer, instead found "%s"\n' "${flag}" "${OPTARG}" exit 1 fi ;; *) printf 'invalid flag: -%s\n' "${flag}" exit 1 ;; esac done tick() { if [[ "${1}" -ge 3600 ]]; then timer_display="$(date -d@"${1}" -u +%H:%M:%S)" else timer_display="$(date -d@"${1}" -u +%M:%S)" fi printf '%s\n' "${timer_display}" if [[ "${1}" -gt 0 ]]; then sleep 1 return 0 else return 1 fi } #hours=1 #minutes=0 #seconds=1 ((total_s = original_time = $((seconds + (minutes * 60) + (hours * 3600))))) #echo "${total_s}" while tick "${total_s}"; do ((total_s--)); done notify-send --urgency=critical --icon=/usr/share/icons/Adwaita/symbolic/status/alarm-symbolic.svg 'Timer elapsed!' "Timer set for $(date -d@"${original_time}" -u +%H:%M:%S) has completed" if [[ -f "/usr/share/sounds/ocean/stereo/alarm-clock-elapsed.oga" ]]; then paplay /usr/share/sounds/ocean/stereo/alarm-clock-elapsed.oga fi