From c4f58e8673b3f73ee23200bf73c67621e8b7dd18 Mon Sep 17 00:00:00 2001 From: novakne Date: Mon, 22 Feb 2021 11:18:55 +0100 Subject: [PATCH 1/3] exemples/scripts: pacman.sh: display number of pacman/aur updates available --- examples/scripts/pacman.sh | 79 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100755 examples/scripts/pacman.sh diff --git a/examples/scripts/pacman.sh b/examples/scripts/pacman.sh new file mode 100755 index 0000000..739dc23 --- /dev/null +++ b/examples/scripts/pacman.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +# +# pacman.sh - display number of packages update available +# by default check every hour +# +# USAGE: pacman.sh +# +# TAGS: +# Name Type Return +# ------------------------------------------- +# {pacman} string number of pacman packages +# {aur} string number of aur packages +# {pkg} string sum of both +# +# Exemple configuration: +# - script: +# path: /absolute/path/to/pacman.sh +# args: [] +# content: { string: { text: " {pacman} + {aur} = {pkg}" } } + + +declare interval no_update aur_helper pacman_num aur_num pkg_num + +# Error message in STDERR +_err() { + printf -- '%s\n' "[$(date +'%Y-%m-%d %H:%M:%S')]: $*" >&2 +} + + +while true; do + # Change interval + # NUMBER[SUFFIXE] + # Possible suffix: + # "s" seconds / "m" minutes / "h" hours / "d" days + interval="1h" + + # Change the message you want when there is no update + # Leave empty if you want a 0 instead of a string + # (e.g. no_update="") + no_update="no update" + + # Change your aur manager + aur_helper="paru" + + # Get number of packages to update + pacman_num=$(checkupdates | wc -l) + + if ! hash "${aur_helper}" >/dev/null 2>&1; then + _err "aur helper not found, change it in the script" + else + aur_num=$("${aur_helper}" -Qmu | wc -l) + fi + + pkg_num=$(( pacman_num + aur_num )) + + # Only display one if there is no update and multiple tags set + if [[ "${pacman_num}" == 0 && "${aur_num}" == 0 ]]; then + pacman_num="${no_update:-$pacman_num}" + aur_num="${no_update:-$aur_num}" + pkg_num="${no_update:-$pkg_num}" + + printf -- '%s\n' "pacman|string|" + printf -- '%s\n' "aur|string|" + printf -- '%s\n' "pkg|string|${pkg_num}" + printf -- '%s\n' "" + else + printf -- '%s\n' "pacman|string|${pacman_num}" + printf -- '%s\n' "aur|string|${aur_num}" + printf -- '%s\n' "pkg|string|${pkg_num}" + printf -- '%s\n' "" + fi + + sleep "${interval}" + +done + +unset -v interval no_update aur_helper pacman_num aur_num pkg_num +unset -f _err + From 0f1c3548aea4f5d7014c02bd92d8365ba246e5a0 Mon Sep 17 00:00:00 2001 From: novakne Date: Tue, 23 Feb 2021 12:00:56 +0100 Subject: [PATCH 2/3] exemples/scripts: pacman.sh: handle no update in yambar config change type to int --- examples/scripts/pacman.sh | 57 +++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/examples/scripts/pacman.sh b/examples/scripts/pacman.sh index 739dc23..53fddb6 100755 --- a/examples/scripts/pacman.sh +++ b/examples/scripts/pacman.sh @@ -6,20 +6,31 @@ # USAGE: pacman.sh # # TAGS: -# Name Type Return +# Name Type Return # ------------------------------------------- -# {pacman} string number of pacman packages -# {aur} string number of aur packages -# {pkg} string sum of both +# {pacman} int number of pacman packages +# {aur} int number of aur packages +# {pkg} int sum of both # -# Exemple configuration: +# Exemples configuration: # - script: -# path: /absolute/path/to/pacman.sh -# args: [] -# content: { string: { text: " {pacman} + {aur} = {pkg}" } } +# path: /absolute/path/to/pacman.sh +# args: [] +# content: { string: { text: "{pacman} + {aur} = {pkg}" } } +# +# To display a message when there is no update: +# - script: +# path: /absolute/path/to/pacman.sh +# args: [] +# content: +# map: +# tag: pkg +# default: { string: { text: "{pacman} + {aur} = {pkg}" } } +# values: +# 0: {string: {text: no updates}} -declare interval no_update aur_helper pacman_num aur_num pkg_num +declare interval aur_helper pacman_num aur_num pkg_num # Error message in STDERR _err() { @@ -34,11 +45,6 @@ while true; do # "s" seconds / "m" minutes / "h" hours / "d" days interval="1h" - # Change the message you want when there is no update - # Leave empty if you want a 0 instead of a string - # (e.g. no_update="") - no_update="no update" - # Change your aur manager aur_helper="paru" @@ -53,27 +59,16 @@ while true; do pkg_num=$(( pacman_num + aur_num )) - # Only display one if there is no update and multiple tags set - if [[ "${pacman_num}" == 0 && "${aur_num}" == 0 ]]; then - pacman_num="${no_update:-$pacman_num}" - aur_num="${no_update:-$aur_num}" - pkg_num="${no_update:-$pkg_num}" - - printf -- '%s\n' "pacman|string|" - printf -- '%s\n' "aur|string|" - printf -- '%s\n' "pkg|string|${pkg_num}" - printf -- '%s\n' "" - else - printf -- '%s\n' "pacman|string|${pacman_num}" - printf -- '%s\n' "aur|string|${aur_num}" - printf -- '%s\n' "pkg|string|${pkg_num}" - printf -- '%s\n' "" - fi + printf -- '%s\n' "pacman|int|${pacman_num}" + printf -- '%s\n' "aur|int|${aur_num}" + printf -- '%s\n' "pkg|int|${pkg_num}" + printf -- '%s\n' "" sleep "${interval}" done -unset -v interval no_update aur_helper pacman_num aur_num pkg_num +unset -v interval aur_helper pacman_num aur_num pkg_num unset -f _err + From 075ddf3f50731ca5e8d576e269a19389c2ea279d Mon Sep 17 00:00:00 2001 From: novakne Date: Tue, 23 Feb 2021 13:44:39 +0100 Subject: [PATCH 3/3] exemples/scripts: pacman.sh: display tags early --- examples/scripts/pacman.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/scripts/pacman.sh b/examples/scripts/pacman.sh index 53fddb6..a20fd6b 100755 --- a/examples/scripts/pacman.sh +++ b/examples/scripts/pacman.sh @@ -37,6 +37,12 @@ _err() { printf -- '%s\n' "[$(date +'%Y-%m-%d %H:%M:%S')]: $*" >&2 } +# Display tags before yambar fetch the updates number +printf -- '%s\n' "pacman|int|0" +printf -- '%s\n' "aur|int|0" +printf -- '%s\n' "pkg|int|0" +printf -- '%s\n' "" + while true; do # Change interval @@ -53,6 +59,7 @@ while true; do if ! hash "${aur_helper}" >/dev/null 2>&1; then _err "aur helper not found, change it in the script" + exit 1 else aur_num=$("${aur_helper}" -Qmu | wc -l) fi @@ -71,4 +78,3 @@ done unset -v interval aur_helper pacman_num aur_num pkg_num unset -f _err -