diff --git a/cmd/publish.go b/cmd/publish.go index aaec35e9..c15761ab 100644 --- a/cmd/publish.go +++ b/cmd/publish.go @@ -69,6 +69,7 @@ Examples: ntfy pub --icon="http://some.tld/icon.png" 'Icon!' # Send notification with custom icon ntfy pub --attach="http://some.tld/file.zip" files # Send ZIP archive from URL as attachment ntfy pub --file=flower.jpg flowers 'Nice!' # Send image.jpg as attachment + echo 'message' | ntfy publish mytopic # Send message from stdin ntfy pub -u phil:mypass secret Psst # Publish with username/password ntfy pub --wait-pid 1234 mytopic # Wait for process 1234 to exit before publishing ntfy pub --wait-cmd mytopic rsync -av ./ /tmp/a # Run command and publish after it completes @@ -254,6 +255,15 @@ func parseTopicMessageCommand(c *cli.Context) (topic string, message string, com if c.String("message") != "" { message = c.String("message") } + if message == "" && isStdinRedirected() { + var data []byte + data, err = io.ReadAll(io.LimitReader(c.App.Reader, 1024*1024)) + if err != nil { + log.Debug("Failed to read from stdin: %s", err.Error()) + return + } + message = strings.TrimSpace(string(data)) + } return } @@ -312,3 +322,12 @@ func runAndWaitForCommand(command []string) (message string, err error) { log.Debug("Command succeeded after %s: %s", runtime, prettyCmd) return fmt.Sprintf("Command succeeded after %s: %s", runtime, prettyCmd), nil } + +func isStdinRedirected() bool { + stat, err := os.Stdin.Stat() + if err != nil { + log.Debug("Failed to stat stdin: %s", err.Error()) + return false + } + return (stat.Mode() & os.ModeCharDevice) == 0 +} diff --git a/docker-compose.yml b/docker-compose.yml index d39492e8..d634600c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,3 @@ -version: "2.1" services: ntfy: image: binwiederhier/ntfy @@ -14,4 +13,3 @@ services: ports: - 80:80 restart: unless-stopped - diff --git a/docs/config.md b/docs/config.md index 0e677f75..cbf34847 100644 --- a/docs/config.md +++ b/docs/config.md @@ -79,7 +79,6 @@ using Docker Compose (i.e. `docker-compose.yml`): === "Docker Compose (w/ auth, cache, attachments)" ``` yaml - version: '3' services: ntfy: image: binwiederhier/ntfy @@ -101,7 +100,6 @@ using Docker Compose (i.e. `docker-compose.yml`): === "Docker Compose (w/ auth, cache, web push, iOS)" ``` yaml - version: '3' services: ntfy: image: binwiederhier/ntfy diff --git a/docs/index.md b/docs/index.md index c63b7709..307463ed 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3,9 +3,9 @@ ntfy lets you **send push notifications to your phone or desktop via scripts fro or POST requests. I use it to notify myself when scripts fail, or long-running commands complete. ## Step 1: Get the app - - - + + + To [receive notifications on your phone](subscribe/phone.md), install the app, either via Google Play, App Store or F-Droid. Once installed, open it and subscribe to a topic of your choosing. Topics don't have to explicitly be created, so just diff --git a/docs/install.md b/docs/install.md index e71bac52..42c868fc 100644 --- a/docs/install.md +++ b/docs/install.md @@ -280,8 +280,6 @@ docker run \ Using docker-compose with non-root user and healthchecks enabled: ```yaml -version: "2.3" - services: ntfy: image: binwiederhier/ntfy diff --git a/docs/integrations.md b/docs/integrations.md index c7da21f9..23c5f9e9 100644 --- a/docs/integrations.md +++ b/docs/integrations.md @@ -95,6 +95,7 @@ I've added a ⭐ to projects or posts that have a significant following, or had - [wlzntfy](https://github.com/Walzen-Group/ntfy-toaster) - A minimalistic, receive-only toast notification client for Windows 11 - [Ntfy_CSV_Reminders](https://github.com/thiswillbeyourgithub/Ntfy_CSV_Reminders) - A Python tool that sends random-timing phone notifications for recurring tasks by using daily probability checks based on CSV-defined frequencies. - [Daily Fact Ntfy](https://github.com/thiswillbeyourgithub/Daily_Fact_Ntfy) - Generate [llm](https://github.com/simonw/llm) generated fact every day about any topic you're interested in. +- [ntfyexec](https://github.com/alecthomas/ntfyexec) - Send a notification through ntfy.sh if a command fails ## Projects + scripts diff --git a/docs/static/img/badge-appstore.png b/docs/static/img/badge-appstore.png index 0b4ce1c0..a8bc73a6 100644 Binary files a/docs/static/img/badge-appstore.png and b/docs/static/img/badge-appstore.png differ diff --git a/docs/static/img/badge-fdroid.png b/docs/static/img/badge-fdroid.png index 9464d38a..c1fc8492 100644 Binary files a/docs/static/img/badge-fdroid.png and b/docs/static/img/badge-fdroid.png differ diff --git a/docs/static/img/badge-googleplay.png b/docs/static/img/badge-googleplay.png index 36036d8b..7a06997a 100644 Binary files a/docs/static/img/badge-googleplay.png and b/docs/static/img/badge-googleplay.png differ diff --git a/docs/subscribe/phone.md b/docs/subscribe/phone.md index e88ff0fb..ab0cedb3 100644 --- a/docs/subscribe/phone.md +++ b/docs/subscribe/phone.md @@ -4,9 +4,9 @@ to receive notifications directly on your phone. Just like the server, this app on GitHub ([Android](https://github.com/binwiederhier/ntfy-android), [iOS](https://github.com/binwiederhier/ntfy-ios)). Feel free to contribute, or [build your own](../develop.md). - - - + + + You can get the Android app from both [Google Play](https://play.google.com/store/apps/details?id=io.heckel.ntfy) and from [F-Droid](https://f-droid.org/en/packages/io.heckel.ntfy/). Both are largely identical, with the one exception that