#!/usr/bin/env bash archpath=/home/hate/.config/polybar/scripts/arch/ #trap 'exit' SIGINT function main_loop { while true; do echo '' > ${archpath}status check_for_updates sleep 600 done } function status { echo $$ > ${archpath}polybar_updates.pid while true; do cat ${archpath}status sleep 1 done } function check_for_updates { checkupdates | nl -w2 -s '. ' >| ${archpath}repo.pkgs yay -Qu --aur | nl -w2 -s '. ' >| ${archpath}aur.pkgs updates=$(cat ${archpath}*.pkgs | wc -l) echo "0" >| ${archpath}status [ $updates -gt 0 ] && echo "%{F#e60053}$updates" >| ${archpath}status >| ${archpath}packages [ -s ${archpath}repo.pkgs ] && cat ${archpath}repo.pkgs >> ${archpath}packages [ -s ${archpath}repo.pkgs ] && [ -s ${archpath}aur.pkgs ] && printf "\n" >> ${archpath}packages [ -s ${archpath}aur.pkgs ] && sed '1iAUR Updates' ${archpath}aur.pkgs >> ${archpath}packages } function notify { if [[ $(${archpath}status) -eq 0 ]] then notify-send 0 else notify-send "$(cat ${archpath}packages)" fi } function upgrade { urxvt -e yay --noconfirm -Syu echo "0" > ${archpath}status } [[ $# -eq 0 ]] && main_loop [[ $1 == "-s" ]] && status [[ $1 == "-c" ]] && echo '' > ${archpath}status && check_for_updates [[ $1 == "-n" ]] && notify