exemples/scripts: pacman.sh: handle no update in yambar config

change type to int
This commit is contained in:
novakne 2021-02-23 12:00:56 +01:00
parent c4f58e8673
commit 0f1c3548ae
No known key found for this signature in database
GPG key ID: 327873BEC52A3176

View file

@ -6,20 +6,31 @@
# USAGE: pacman.sh # USAGE: pacman.sh
# #
# TAGS: # TAGS:
# Name Type Return # Name Type Return
# ------------------------------------------- # -------------------------------------------
# {pacman} string number of pacman packages # {pacman} int number of pacman packages
# {aur} string number of aur packages # {aur} int number of aur packages
# {pkg} string sum of both # {pkg} int sum of both
# #
# Exemple configuration: # Exemples configuration:
# - script: # - script:
# path: /absolute/path/to/pacman.sh # path: /absolute/path/to/pacman.sh
# args: [] # args: []
# content: { string: { text: " {pacman} + {aur} = {pkg}" } } # 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 # Error message in STDERR
_err() { _err() {
@ -34,11 +45,6 @@ while true; do
# "s" seconds / "m" minutes / "h" hours / "d" days # "s" seconds / "m" minutes / "h" hours / "d" days
interval="1h" 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 # Change your aur manager
aur_helper="paru" aur_helper="paru"
@ -53,27 +59,16 @@ while true; do
pkg_num=$(( pacman_num + aur_num )) pkg_num=$(( pacman_num + aur_num ))
# Only display one if there is no update and multiple tags set printf -- '%s\n' "pacman|int|${pacman_num}"
if [[ "${pacman_num}" == 0 && "${aur_num}" == 0 ]]; then printf -- '%s\n' "aur|int|${aur_num}"
pacman_num="${no_update:-$pacman_num}" printf -- '%s\n' "pkg|int|${pkg_num}"
aur_num="${no_update:-$aur_num}" printf -- '%s\n' ""
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}" sleep "${interval}"
done 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 unset -f _err