diff options
| author | Fuwn <[email protected]> | 2024-09-23 00:37:43 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-09-23 00:37:43 -0700 |
| commit | 7ac881cea13d72ef80c287118cd30d63fbbfd5f3 (patch) | |
| tree | ebec24c389205868de22f130e94b903653699473 | |
| parent | acd236a56227f11219085fe0745becb193911973 (diff) | |
| download | rui-7ac881cea13d72ef80c287118cd30d63fbbfd5f3.tar.xz rui-7ac881cea13d72ef80c287118cd30d63fbbfd5f3.zip | |
feat(rui): custom notifier support
| -rw-r--r-- | README.md | 31 | ||||
| -rw-r--r-- | flake.nix | 2 | ||||
| -rw-r--r-- | rui.go | 15 |
3 files changed, 43 insertions, 5 deletions
@@ -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 @@ -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="; @@ -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 |