diff --git a/usr/local/bin/sh.zio.notify b/usr/local/bin/sh.zio.notify index b523a91..10be2bc 100755 --- a/usr/local/bin/sh.zio.notify +++ b/usr/local/bin/sh.zio.notify @@ -5,20 +5,11 @@ _PLUG_DESCRIPTION="" _PLUG_ARGS=( "message;m;;string;(No Message)" "title;t;;string;(No Title)" + "file;f;;path" "level;l;;string;info" "invoked-by;i;;string" ) -function get_cache_header() { - topic="$1" - - if [[ "$topic" == "zio_test" ]]; then - echo "" - else - echo "Cache: no" - fi -} - function get_level_emoji() { case "$1" in "critical"|"error") echo "⛔" ;; @@ -75,11 +66,28 @@ function main() { "topic": "'$n_topic'" }' - curl -d "$body" \ - -H "Authorization: Bearer $token" \ - -H "$(get_cache_header "$n_topic")" \ - -H "Markdown: yes" \ - "https://ntfy.zio.sh/" + curl_command="curl -d \"$body\"" + curl_command+=" -H \"Authorization: Bearer $token\"" + curl_command+=" -H \"Markdown: yes\"" + + if [[ "$n_topic" == "zio_test" ]]; then + curl_command+=" -H \"Cache: no\"" + fi + + if [[ "$_file" != "" ]]; then + if [[ ! -f "$_file" ]]; then + die "Cannot attach '$_file': file does not exist" + fi + + full_file="$(realpath -s "$_file")" + + curl_command+=" -T \"$full_file\"" + curl_command+=" -H \"Filename: $(basename "$full_file")\"" + fi + + curl_command+=" https://ntfy.zio.sh/" + + echo $curl_command } if [[ $_PLUG_INVOKED != "true" ]]; then