#!/usr/bin/env bash . ~/bin/i3blocks/_utils # Check if updated Arch packages can be installed pkgupdate() { local pkgcount=$(checkupdates | wc -l) local seconds_since_last_patched=$(echo "$(date +%s) - $(stat -c %Y /var/log/pacman.log)" | bc -l) local hours_since_last_patched=$(echo "scale=0; $seconds_since_last_patched / 60 / 60" | bc -l) local hours_to_consider_stale=168 # Few updates if [[ $pkgcount -ge 1 && $pkgcount -lt 35 ]]; then if [[ $hours_since_last_patched -gt $hours_to_consider_stale ]]; then local bg=$warn1_bg local fg=$warn1_fg else local bg=$info_bg local fg=$info_fg fi # Many updates elif [[ $pkgcount -ge 35 ]]; then if [[ $hours_since_last_patched -gt $hours_to_consider_stale ]]; then local bg=$crit_bg local fg=$crit_fg else local bg=$warn2_bg local fg=$warn2_fg fi fi if ((hours_since_last_patched >= 24)); then local time_str="$(awk "BEGIN {printf \"%.1f\", int($hours_since_last_patched / 24 * 2 + 0.5) / 2}")d" else local time_str="${hours_since_last_patched}h" fi local stat="$pkgcount pkg updates (last update: ${time_str} ago)" if [[ -n "$bg" ]]; then echo -e "$stat\n" fi } pkgupdate