Add support for max notification amount in gh-notify

This commit is contained in:
ItsDrike 2023-01-25 12:50:15 +01:00
parent 9293df67bf
commit ed1487a251
No known key found for this signature in database
GPG key ID: B014E761034AF742

View file

@ -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