#!/bin/sh -e
#
# notify - send notification

pri=0
to=5000
[ "$1" = "--pri" ] && shift && pri=1
[ "$1" = "-t" ] && shift && to="$1" && shift
if command -v fyi >/dev/null 2>&1; then
  notifysend="fyi"
else
  notifysend="notify-send"
fi

case "$(uname)" in
  Darwin)
    if [ -n "$2" ]; then
      osascript -e "display notification \"${2}\" with title \"${1}\""
    else
      osascript -e "display notification \"${1}\" with title \"Notification\""
    fi
    ;;
  *)
    if [ "${pri}" = "1" ]; then
      ${notifysend} --urgency=critical -t "${to}" "${1:-Notification}" "${2}" >/dev/null 2>/dev/null
    else
      ${notifysend} -t "${to}" "${1:-Notification}" "${2}" >/dev/null 2>/dev/null
    fi
    # if command -v dunstctl >/dev/null 2>&1; then
    #   timestamp=$(date +%T)
    #   dcount=$(dunstctl count history)
    #   notify-send --transient --expire-time=3000 "${timestamp}" "${dcount} notification(s)"
    # fi
esac
