diff --git a/.config/waybar/config.jsonc b/.config/waybar/config.jsonc index 7a49f8b..f325e0f 100644 --- a/.config/waybar/config.jsonc +++ b/.config/waybar/config.jsonc @@ -86,8 +86,9 @@ "interval": 60, "tooltip": true, "format": "{} ", + "return-type": "json", "exec": "$HOME/.config/waybar/scripts/check-updates.sh", - "exec-if": "[[ `$HOME/.config/waybar/scripts/check-updates.sh` != 0 ]]", + "exec-if": "[[ `checkupdates | wc -l` != 0 ]]", "signal": 1 }, "custom/recorder": { diff --git a/.config/waybar/scripts/check-updates.sh b/.config/waybar/scripts/check-updates.sh index c514bef..d8b0a35 100755 --- a/.config/waybar/scripts/check-updates.sh +++ b/.config/waybar/scripts/check-updates.sh @@ -1,7 +1,14 @@ -#! /usr/bin/env bash +#!/usr/bin/env bash main() { - checkupdates | wc -l + updates=$(checkupdates --nocolor 2>/dev/null) + if [[ $? -ne 0 || -z "$updates" ]]; then + echo '{"text": "", "tooltip": ""}' | jq --unbuffered --compact-output + else + numberOfUpdates=$(echo "$updates" | wc -l) + tooltip=$(echo "$updates" | sed 's/\n/\r/g' | jq -sR .) + echo "{\"text\": \"$numberOfUpdates\", \"tooltip\": $tooltip}" | jq --unbuffered --compact-output + fi } -main $@ \ No newline at end of file +main "$@" \ No newline at end of file