From 45ecf8c37639a8ed39159c36fc35b5ae00239419 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sat, 17 Jun 2023 11:38:58 +0200 Subject: [PATCH] Update scripts to use cntfy as a library --- cntfy | 46 +++++++++++++++++++ cntfy.nu | 34 +------------- pacman-update-check.nu => pacman-update-check | 4 +- 3 files changed, 50 insertions(+), 34 deletions(-) create mode 100755 cntfy rename pacman-update-check.nu => pacman-update-check (85%) diff --git a/cntfy b/cntfy new file mode 100755 index 0000000..15f326b --- /dev/null +++ b/cntfy @@ -0,0 +1,46 @@ +#!/usr/bin/env nu + +use ./cntfy.nu + +def main [ + subcommand: string@subcommands +] { + if $subcommand == "help" { + print $"cntfy ", + print "" + print "Subcommands: " + + for subcommand in ( subcommands ) { + print "" + print $"(ansi {attr: b})($subcommand)(ansi reset)" + print ( help $"main ($subcommand)" ) + } + } else { + let span = (metadata $subcommand).span; + error make { + msg: $"Unknown subcommand ($subcommand)", + label: { + text: "Unknown subcommand", + start: $span.start, + end: $span.end + } + } + } +} + +def subcommands [] { + ["publish"] +} + +# Publishes a message with certain properties +def `main publish` [ + topic: string + message: string + --title: string + --priority: number + --tags: list + --actions: list + --icon: string +] { + cntfy publish $topic $message --title $title --priority $priority --tags $tags --actions $actions --icon $icon +} diff --git a/cntfy.nu b/cntfy.nu index 3745af2..cd8fcda 100755 --- a/cntfy.nu +++ b/cntfy.nu @@ -1,37 +1,5 @@ -#!/usr/bin/env nu - -def main [ - subcommand: string@subcommands -] { - if $subcommand == "help" { - print $"cntfy ", - print "" - print "Subcommands: " - - for subcommand in ( subcommands ) { - print "" - print $"(ansi {attr: b})($subcommand)(ansi reset)" - print ( help $"main ($subcommand)" ) - } - } else { - let span = (metadata $subcommand).span; - error make { - msg: $"Unknown subcommand ($subcommand)", - label: { - text: "Unknown subcommand", - start: $span.start, - end: $span.end - } - } - } -} - -def subcommands [] { - ["publish"] -} - # Publishes a message -export def `main publish` [ +export def publish [ topic: string message: string --title: string diff --git a/pacman-update-check.nu b/pacman-update-check similarity index 85% rename from pacman-update-check.nu rename to pacman-update-check index 90f26b6..e22afd7 100755 --- a/pacman-update-check.nu +++ b/pacman-update-check @@ -11,6 +11,8 @@ def main [ msg: "This script needs to be run as root" } } + pacman -Sy + let updates = ( checkupdates | split row "\n" ) let update_count = ( $updates | length ) @@ -28,7 +30,7 @@ def main [ } else { $update_msg = ( $updates | str join "\n" ) } - cntfy main publish --title $"($update_count) package[s] need to be updated" updates $update_msg + cntfy publish --title $"($update_count) package[s] need to be updated" updates $update_msg } } } \ No newline at end of file