Created
June 30, 2023 07:32
-
-
Save niksingh710/68c7ba2cd535d96e048caa8a527c58e9 to your computer and use it in GitHub Desktop.
Waybar Arch Linux Custom Update Module. Including AUR with (checkupdates-with-aur)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"custom/updates": { | |
"format": "{}", | |
"interval": 3600, | |
"exec": "~/.config/waybar/scripts/updatecheck", | |
"return-type": "json", | |
"exec-if": "exit 0", | |
"signal": 8 | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
check() { | |
command -v "$1" 1>/dev/null | |
} | |
notify() { | |
check notify-send && { | |
notify-send "$@" | |
return | |
} | |
echo "$@" | |
} | |
stringToLen() { | |
STRING="$1" | |
LEN="$2" | |
if [ ${#STRING} -gt "$LEN" ]; then | |
echo "${STRING:0:$((LEN - 2))}.." | |
else | |
printf "%-20s" "$STRING" | |
fi | |
} | |
check checkupdates-with-aur || { | |
cat <<EOF | |
{"text":"ERR","tooltip":"checkupdates-with-aur is not installed"} | |
EOF | |
exit 1 | |
} | |
IFS=$'\n'$'\r' | |
killall -q checkupdates-with-aur | |
mapfile -t updates < <(checkupdates-with-aur) | |
text=${#updates[@]} | |
tooltip="<b>$text updates (arch+aur) </b>\n" | |
tooltip+=" <b>$(stringToLen "PkgName" 20) $(stringToLen "PrevVersion" 20) $(stringToLen "NextVersion" 20)</b>\n" | |
[ "$text" -eq 0 ] && text="" || text+=" " | |
for i in "${updates[@]}"; do | |
# shellcheck disable=2046 | |
update="$(stringToLen $(echo "$i" | awk '{print $1}') 20)" | |
# shellcheck disable=2046 | |
prev="$(stringToLen $(echo "$i" | awk '{print $2}') 20)" | |
# shellcheck disable=2046 | |
next="$(stringToLen $(echo "$i" | awk '{print $4}') 20)" # skipping '->' string | |
tooltip+="<b> $update </b>$prev $next\n" | |
done | |
tooltip=${tooltip::-2} | |
cat <<EOF | |
{ "text":"$text", "tooltip":"$tooltip"} | |
EOF | |
# vim: ft=sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a preview of waybar tool tip.
Dependencies
Waybar
Arch Linux
checkupdates-with-aur