M ntfy.el => ntfy.el +22 -31
@@ 4,8 4,8 @@
;; Author: Shom Bandopadhaya <shom@bandopadhaya.com>
;; Created: 2022-04-30
-;; Modified: 2022-04-30
-;; Version: 0.1.1
+;; Modified: 2022-05-04
+;; Version: 0.1.2
;; Keywords: ntfy notification push-notification pub-sub
;; Package-Requires: ((emacs "27.2") (curl))
;; SPDX-License-Identifier: MIT
@@ 33,58 33,49 @@
:type 'string)
(defcustom ntfy-tags nil
- "Set the emoji that'll appear before the header message. Use comma separated string, see https://ntfy.sh/docs/publish/#tags-emojis for details."
+ "Set the emoji that'll appear before the header message.
+Use comma separated string, see https://ntfy.sh/docs/publish/#tags-emojis for details."
:group 'ntfy
:type 'string)
-(defvar ntfy--message nil
- "Message string that will be published.")
-
-(defvar ntfy--link nil
- "URL that will be published.")
-
(defun ntfy-send-message (message)
"Send ad-hoc MESSAGE from mini-buffer as notification."
(interactive "sEnter message:")
- (setq ntfy--message message)
- (ntfy--publish-message))
+ (ntfy--publish-message message))
(defun ntfy-send-message-with-header (header message)
"Send ad-hoc MESSAGE from mini-buffer with custom HEADER as notification."
(interactive "sEnter header: \nsEnter message: ")
(setq ntfy-header header)
- (setq ntfy--message message)
- (ntfy--publish-message))
+ (ntfy--publish-message message header))
(defun ntfy-send-message-with-header-and-tags (tags header message)
- "Send ad-hoc MESSAGE from mini-buffer with custom HEADER and TAGS as notification."
+ "Send ad-hoc MESSAGE from mini-buffer.
+Custom HEADER and TAGS are set for the notification."
(interactive "sEnter tags (emoji codes, comma separated no spaces): \nsEnter header: \nsEnter message: ")
- (setq ntfy-tags tags)
- (setq ntfy-header header)
- (setq ntfy--message message)
- (ntfy--publish-message))
-
-(defun ntfy--publish-message ()
-"Publish message to server with curl."
-(start-process "nfty.el" nil "curl"
- "-H" (format "Title: %s" ntfy-header)
- "-H" (format "Tags: %s" ntfy-tags)
- "-d" (format "%s" ntfy--message)
+ (ntfy--publish-message message header tags))
+
+(defun ntfy--publish-message (message &optional header tags)
+ "Publish message to server with curl with MESSAGE.
+Configured HEADER and TAGS are used unless specified."
+ (start-process "nfty.el" nil "curl"
+ "-H" (format "Title: %s" (or header ntfy-header))
+ "-H" (format "Tags: %s" (or tags ntfy-tags))
+ "-d" (format "%s" message)
(format "%s/%s" ntfy-server ntfy-topic)))
(defun ntfy-send-url (url)
"Send URL from mini-buffer."
(interactive "sEnter URL: \n")
- (setq ntfy--link url)
- (ntfy--publish-url))
+ (ntfy--publish-url url))
-(defun ntfy--publish-url ()
-"Publish url to server with curl."
+(defun ntfy--publish-url (url)
+"Publish URL to server with curl."
(start-process "nfty.el" nil "curl"
"-H" (format "Title: %s" "Emacs shared a URL")
"-H" (format "Tags: %s" "link")
- "-H" (format "Actions: view, %s, %s" ntfy--link ntfy--link)
- "-d" (format "%s" ntfy--link)
+ "-H" (format "Actions: view, %s, %s" url url)
+ "-d" (format "%s" url)
(format "%s/%s" ntfy-server ntfy-topic)))
(provide 'ntfy)
M readme.org => readme.org +22 -5
@@ 25,13 25,30 @@ The following custom variables must be configured:
- =ntfy-tags=: The emoji(s) that'll appear before the header message. Use comma separated (no spaces) string, see https://ntfy.sh/docs/publish/#tags-emojis for details.
* Usage
-Once the package is loaded and configured a notification can be sent by invoking the command =ntfy-send-message= interactively or programmatically =ntfy-send-message(STRING)=.
+Once the package is loaded and configured a notification can be sent by invoking the following commands interactively or programmatically:
+
+|----------------------------------------+--------------------------------------------------------------|
+| Interactive | Programmatic |
+|----------------------------------------+--------------------------------------------------------------|
+| =ntfy-send-message= | ~(ntfy-send-message MESSAGE)~ |
+| =ntfy-send-message-with-header= | ~(ntfy-send-message-with-header HEADER MESSAGE)~ |
+| =ntfy-send-message-with-header-and-tags= | ~(ntfy-send-message-with-header-and-tags TAGS HEADER MESSAGE)~ |
+| =ntfy-send-url= | ~(ntfy-send-url URL)~ |
+|----------------------------------------+--------------------------------------------------------------|
* Improvements
This is the first Emacs package I've put together, contributions, suggestions for best practices, and constructive criticism is very much welcome and appreciated.
-Here are some of
-- Improve documentation and testing. There isn't an ounce of error or dependency checking. This has only been tested on =Emacs 28.0.91= using =curl 7.68.0=.
+Here are some of the potential improvements:
+- Improve documentation and testing.
+ - [X] This has been tested on =Emacs 27.2= & =28.0.92= using =curl= on Pop!_OS (20.04 and 22.04) and Termux.
+ - [X] All functions are documented and there are no Flycheck errors or warnings.
+ - [ ] Test on other OSes.
- Provide more functionality:
- - Interactively and programmatically set the tag per message as an optional parameter.
- - Provide minor mode to capture all Emacs notifications and post them to pre-defined topics.
+ - [X] Interactively and programmatically set the tag per message as an optional parameter.
+ - [X] Send URL as a clickable item from the Android notification shade.
+ - [ ] Send a file attachment.
+ - [ ] Send Android intents.
+ - Stretch:
+ - [ ] Provide templates for Header and Tags as a pop-up selection list.
+ - [ ] Provide minor mode to capture all Emacs notifications and post them to pre-defined topics.