From 0f1c3548aea4f5d7014c02bd92d8365ba246e5a0 Mon Sep 17 00:00:00 2001 From: novakne Date: Tue, 23 Feb 2021 12:00:56 +0100 Subject: [PATCH] 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 +