#!/usr/bin/env zsh # author: Daniel Sommer # license: MIT # usage: # notify.sh [options] # documentation @ https://docs.ntfy.sh/publish url="https://notify.velvettear.de" user="velvettear" password="\$Velvet90" [[ -z "$1" ]] && printf "error: no topic specified\n" 1>&2 && exit 1 [[ -z "$2" ]] && printf "error: no payload specified\n" 1>&2 && exit 1 url="$url/$1" payload="$2" # check if payload is a file if [[ -e "$payload" ]]; then args+=("-T" "$(realpath $payload)" "-H" "Filename: $(basename $payload)") else args+=("-d" "$payload") fi # check for valid priority level function checkPriority() { prio="$(printf "$1" | tr '[:upper:]' '[:lower:]')" if [[ "$prio" == "min" ]] || [[ "$prio" == "low" ]] || [[ "$prio" == "default" ]] || [[ "$prio" == "high" ]] || [[ "$prio" == "max" ]] || [[ "$prio" == "urgent" ]]; then args+=("-H" "Priority: $prio") fi } # check arguments index=1 for arg in "$@"; do ((index++)) value="${@[$index]}" case "$arg" in -e|--emoji|-i|--icon) args+=("-H" "Tags: $value") ;; -p|--priority) checkPriority "$value" ;; -t|--title) args+=("-H" "Title: $value") ;; esac done curl -s -u $user:$password ${args[@]} $url