diff --git a/roles/waybar/files/waybar/modules/pkg.sh b/roles/waybar/files/waybar/modules/pkg.sh index 1be608b..aa86729 100755 --- a/roles/waybar/files/waybar/modules/pkg.sh +++ b/roles/waybar/files/waybar/modules/pkg.sh @@ -1,21 +1,18 @@ #!/bin/bash pacman_check() { - pac=$(checkupdates 2>/dev/null | wc -l) - aur=$(trizen -Qua 2>/dev/null | wc -l) + pac=$(checkupdates 2>/dev/null) + pac_count=$(wc -l <<< "$pac") + aur=$(trizen -Qua 2>/dev/null) + aur_count=$(wc -l <<< "$aur") - if [[ $pac -eq "0" ]] && [[ $aur -eq "0" ]] || [[ ! $pac =~ [0-9]+ ]] || [[ ! $aur =~ [0-9]+ ]] + if [[ $pac_count -eq "0" ]] && [[ $aur_count -eq "0" ]] || [[ ! $pac_count =~ [0-9]+ ]] || [[ ! $aur_count =~ [0-9]+ ]] then exit 0 fi - - if checkupdates | grep '^linux\ ' - then - echo "$pac $aur" - else - #echo "$pac %{F#5b5b5b}%{F-} $aur" - echo "$pac $aur" - fi + + text="$pac $aur" + tooltip=$(awk -v ORS='\\n' '$0=$1' <<< "$pac$aur") } xbps_check(){ @@ -26,9 +23,9 @@ xbps_check(){ then exit 0 fi + text=" $pkg_count" - tooltip=$(awk '$0=$1' ORS='\\n' <<< "$pkg") - printf '{"text": "%s", "tooltip": "%s"}' "$text" "$tooltip" + tooltip=$(awk -v ORS='\\n' '$0=$1' <<< "$pkg") } if grep -i "arch" /etc/os-release &>/dev/null @@ -38,3 +35,6 @@ elif grep -i "void" /etc/os-release &>/dev/null then xbps_check fi + +# Print json +printf '{"text": "%s", "tooltip": "%s"}' "$text" "$tooltip"