From 9567af879f7f45f5f1a381ebe8c0780ac8c0ba79 Mon Sep 17 00:00:00 2001 From: Oliver Ladner Date: Sun, 21 Jun 2026 14:02:26 +0200 Subject: [PATCH] feat(archupdates): colorize output depending on last update date too --- home/oli/bin/i3blocks/archupdates | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/home/oli/bin/i3blocks/archupdates b/home/oli/bin/i3blocks/archupdates index 0da4bbb..0fd54be 100755 --- a/home/oli/bin/i3blocks/archupdates +++ b/home/oli/bin/i3blocks/archupdates @@ -5,14 +5,29 @@ # Check if updated Arch packages can be installed pkgupdate() { local pkgcount=$(checkupdates | wc -l) - if [[ $pkgcount -ge 1 && $pkgcount -lt 20 ]]; then - local bg=$mute_bg - local fg=$mute_fg - elif [[ $pkgcount -ge 20 ]]; then - local bg=$warn1_bg - local fg=$warn1_fg + 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 - local stat="$pkgcount pkg updates" + local stat="$pkgcount pkg updates (last update: $hours_since_last_patched hours ago)" if [[ -n "$bg" ]]; then echo -e "$stat\n"