Initial commit with actual script and README

This commit is contained in:
r000t 2024-12-16 15:20:38 -05:00
parent 07b09fc094
commit e59d8d0a37
2 changed files with 107 additions and 1 deletions

View File

@ -1,3 +1,40 @@
# ding
The fastest way to set up push notifications on-demand
The fastest way to set up push notifications on-demand using [ntfy.sh](https://ntfy.sh/).
Install the ntfy.sh app on your phone, drop this script into your $PATH, set the topic on both ends, and you're done.
Follow any long running command with `ding` to get a push notification when it finishes.
It's that easy. ntfy.sh does not require registration.
## Installation
Copy script to a directory in your $PATH, such as `/usr/local/bin`
`mv ding /usr/local/bin/ding`
Edit the `NTFY_TOPIC` variable at the top of the file to a topic of your choosing.
```bash
# Define your ntfy.sh topic
NTFY_TOPIC="your-topic-name"
```
Treat this like a password. Anybody who knows the topic can see and send notifications.
## How to Use It
Follow any long-running command with `ding`.
`make && make install; ding`
## Options
### Title
Any text after `ding` will become the title of the notification.
`ding Task Completed.`
### Priority
Priority in ntfy.sh represents a "preset" for how intrusive the notification is.
`--min`, `--low`, `--high`, and `--max` correspond to these options.
Read the [message priority](https://docs.ntfy.sh/publish/#message-priority) docs for more information.

69
ding Executable file
View File

@ -0,0 +1,69 @@
#!/bin/bash
# Define your ntfy.sh topic
NTFY_TOPIC="YOUR_TOPIC_GOES_HERE"
NTFY_BASE_URL="https://ntfy.sh"
# Default titles, tags, and messages
SUCCESS_TITLE="Ding: Succeess"
SUCCESS_TAG="heavy_check_mark"
SUCCESS_MESSAGE="Command completed successfully."
FAILURE_TITLE="Ding: Failure"
FAILURE_TAG="x"
FAILURE_MESSAGE="Command encountered an error."
# Parse arguments for priority or overrides
CUSTOM_MESSAGE=""
CUSTOM_TITLE=""
while [[ $# -gt 0 ]]; do
case "$1" in
--message)
CUSTOM_MESSAGE="$2"
shift 2
;;
--max)
PRIORITY="5"
shift
;;
--high)
PRIORITY="4"
shift
;;
--low)
PRIORITY="2"
shift
;;
--min)
PRIORITY="1"
shift
;;
*)
CUSTOM_TITLE="$1"
shift
;;
esac
done
# Capture the exit status of the last command
STATUS_CODE=$?
# Determine the notification content
if [ $STATUS_CODE -eq 0 ]; then
TITLE="${CUSTOM_TITLE:-$SUCCESS_TITLE}"
TAG="$SUCCESS_TAG"
MESSAGE="${CUSTOM_MESSAGE:-$SUCCESS_MESSAGE}"
else
TITLE="${CUSTOM_TITLE:-$FAILURE_TITLE}"
TAG="$FAILURE_TAG"
MESSAGE="${CUSTOM_MESSAGE:-$FAILURE_MESSAGE} Exit code: $STATUS_CODE."
fi
# Send the notification
curl -X POST "$NTFY_BASE_URL/$NTFY_TOPIC" \
-H "Title: $TITLE" \
-H "Tags: $TAG" \
-H "Priority: $PRIORITY" \
-d "$MESSAGE"
# Optional: echo the notification for debugging
echo "Notification sent with title: $TITLE, tag: $TAG, message: $MESSAGE, priority: $PRIORITY, and status code: $STATUS_CODE"