From d19e14a3e2bc885c64aaf4fab63e064abd096328 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 23 Sep 2024 07:37:43 +0000 Subject: feat(rui): custom notifier support --- README.md | 31 +++++++++++++++++++++++++++++++ flake.nix | 2 +- rui.go | 15 +++++++++++---- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ef9ccf0..49caf34 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,9 @@ inputs.home-manager.lib.homeManagerConfiguration { # Status notifications via `notify-send` notify = true; + # The command to use for sending notifications, view a cool example below! + notifier = "notify-send"; + # Rui falls back on the `FLAKE_EDITOR` and `EDITOR` environment variables editor = "code"; @@ -81,6 +84,34 @@ rui.packages.${pkgs.system}.default )).packages.${builtins.currentSystem}.default ``` +## Custom Notification Command Example + +Rui uses `notify-send` by default for sending notifications, but you can set +the `notifier` configuration value to any file path. Here's an example of a +distributed notification script that sends notifications to your phone **and** +your PC. This can easily be adapted to send notifications to any service, e.g., +Telegram, Discord, other webhook receivers, etc. + +This example uses [Bark](https://bark.day.app/#/?id=%E6%BA%90%E7%A0%81), an +extremely simple and easy-to-use notification service for iOS devices. + +```sh +#!/usr/bin/env dash + +# Send a notification to your host PC +notify-send "$1" "$2" + +# Send a notification to your iOS device +curl -X "POST" "https://api.day.app/your_bark_api_key" \ + -H 'Content-Type: application/json; charset=utf-8' \ + --silent \ + -d '{ + "body": "'"${2}"'", + "title": "'"${1}"'", + "icon": "https://nixos.wiki/images/thumb/2/20/Home-nixos-logo.png/207px-Home-nixos-logo.png" + }' +``` + ## `--help` ```text diff --git a/flake.nix b/flake.nix index 4068882..d80f3d1 100644 --- a/flake.nix +++ b/flake.nix @@ -41,7 +41,7 @@ { packages.default = pkgs.buildGoModule { pname = "rui"; - version = "2024.09.22"; + version = "2024.09.23"; src = pkgs.lib.cleanSource ./.; vendorHash = "sha256-mN/QjzJ4eGfbW1H92cCKvC0wDhCR6IUes2HCZ5YBdPA="; diff --git a/rui.go b/rui.go index fd18ed4..ea261b7 100644 --- a/rui.go +++ b/rui.go @@ -11,9 +11,10 @@ import ( ) type Configuration struct { - Notify bool `json:"notify"` - Editor string `json:"editor"` - Flake string `json:"flake"` + Notify bool `json:"notify"` + Editor string `json:"editor"` + Flake string `json:"flake"` + Notifier string `json:"notifier"` } type ActionDetails struct { @@ -215,7 +216,13 @@ func notify(message string) error { return nil } - notifySend, err := exec.LookPath("notify-send") + notifier := configuration.Notifier + + if notifier == "" { + notifier = "notify-send" + } + + notifySend, err := exec.LookPath(notifier) if err != nil { return nil -- cgit v1.2.3