From ed1487a2514ee0dbdda9e0d8e7738071210b9dd0 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Wed, 25 Jan 2023 12:50:15 +0100 Subject: [PATCH] Add support for max notification amount in gh-notify --- home/.local/bin/scripts/gui/gh-notification | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/home/.local/bin/scripts/gui/gh-notification b/home/.local/bin/scripts/gui/gh-notification index 42be614..1f47f51 100755 --- a/home/.local/bin/scripts/gui/gh-notification +++ b/home/.local/bin/scripts/gui/gh-notification @@ -10,6 +10,7 @@ TEMP_SHOW=0 DRY_RUN=0 NO_CACHE=0 NO_DISPLAY=0 +MAX_AMOUNT=0 URGENCY="normal" RESET=0 while [ "$1" ]; do @@ -31,6 +32,7 @@ Options: -nd | --no-display: When the script is ran from headless mode (such as by crontab), this will still attempt to set the DISPLAY and send the desktop notification -r | --reset: Resets notification cache (storing which notifications were already sent), skips notification sending, WARNING: removes the whole cache, regardless of '--all') -u | --urgency [urgency-level]: pass over notify-send urgency attribute (low, normal, critical) +-n | --number [amount]: maximum amount of notifications to show EOF exit 0 ;; @@ -66,6 +68,10 @@ EOF URGENCY="$2" shift ;; + -n | --number) + MAX_AMOUNT="$2" + shift + ;; -r | --reset) RESET=1 ;; @@ -182,7 +188,8 @@ send_notify() { # Obtain notifications and show them, if they weren't showed (aren't in cache) already # ------------------------------------------------------------------------------------ # Request unread notifications with gh-notify extension for github-cli -[ "$ALL" -eq 1 ] && out="$(gh notify -s -a)" || out="$(gh notify -s)" +[ "$ALL" -eq 1 ] && out="$(gh notify -s -a -n "$MAX_AMOUNT")" || out="$(gh notify -s -n "$MAX_AMOUNT")" + total="$(printf "%s\n" "$out" | wc -l)" # Since we always end with a newline (to count the last entry as a line), we always get # at least 1 as a total here, even if $out is empty. If we didn't use the \n, we'd always