update ntfy scripts

This commit is contained in:
2026-02-04 17:32:54 -08:00
parent 8c520df5bd
commit b64a2c9030
2 changed files with 42 additions and 5 deletions

View File

@@ -1,14 +1,14 @@
#!/usr/bin/env bash
#
# ntfy-me — run any command, then send ntfy success/failure notification (via curl)
# ntfy-cmd — run any command, then send ntfy success/failure notification (via curl)
#
# Usage:
# ntfy-me <command> [args...]
# ntfy-cmd <command> [args...]
#
# Example:
# ntfy-me make build
# ntfy-me bash -c "sleep 10 && false"
# ntfy-me ls /nonexistent
# ntfy-cmd make build
# ntfy-cmd bash -c "sleep 10 && false"
# ntfy-cmd ls /nonexistent
#
# Notes:
# - Requires $NTFY_ME_TOPIC set (e.g., mytopic)
@@ -76,3 +76,4 @@ curl -fsS -X POST \
"$NTFY_HOST/$NTFY_ME_TOPIC" >/dev/null 2>&1 || echo "Warning: failed to send ntfy notification" >&2
exit $code

36
scripts/ntfy-msg Executable file
View File

@@ -0,0 +1,36 @@
#!/usr/bin/env bash
#
# ntfy-msg — send a message to ntfy (via curl)
#
# Usage:
# ntfy-msg <message>
#
# Example:
# ntfy-msg "Build finished"
#
# Notes:
# - Requires $NTFY_ME_TOPIC set (e.g., mytopic)
# - Optional $NTFY_HOST (defaults to https://ntfy.sh)
set -u
if [ -z "${NTFY_ME_TOPIC:-}" ]; then
echo "Error: NTFY_ME_TOPIC environment variable not set."
echo "Set it like: export NTFY_ME_TOPIC=mytopic"
exit 1
fi
# Set default ntfy host if not provided
NTFY_HOST="${NTFY_HOST:-https://ntfy.sh}"
if [ $# -lt 1 ]; then
echo "Usage: $0 <message>"
exit 1
fi
message="$*"
curl -fsS -X POST \
-d "$message" \
"$NTFY_HOST/$NTFY_ME_TOPIC" >/dev/null 2>&1 || echo "Warning: failed to send ntfy message" >&2