diff --git a/scripts/bar.sh b/scripts/bar.sh index c165430..a5c3541 100755 --- a/scripts/bar.sh +++ b/scripts/bar.sh @@ -13,6 +13,7 @@ icon_wifi=$(icon 048) icon_battery=$(icon 033) icon_battery_charging=$(icon 042) icon_clock=$(icon 018) +icon_updates=$(icon 060) color_service_running="#A0A57E" color_service_stopped="#C37561" @@ -81,6 +82,11 @@ clock() { echo -n "%{A:I "clock 1061":}$icon_clock $info%{A}" } +updates() { + info=$(./cmdcache.sh 1200 checkupdates | wc -l) + echo -n "$icon_updates $info" +} + run_handler() { while read type param; do case $type in @@ -94,7 +100,7 @@ run_handler() { while true; do - echo "%{l} $(music) $(services) $(diskspace)%{r}$(wifi) $(battery) $(clock) " + echo "%{l} $(music) $(services) $(diskspace)%{r}$(updates) $(wifi) $(battery) $(clock) " sleep 1 done | lemonbar -g 1366x15 -f "Terminus:size=8","Stlarch:size=6:style=regular" -B "#88000000" | run_handler diff --git a/scripts/cmdcache.sh b/scripts/cmdcache.sh new file mode 100755 index 0000000..00a8444 --- /dev/null +++ b/scripts/cmdcache.sh @@ -0,0 +1,24 @@ +#!/bin/bash +#Arguments +CMD=$2 +CACHE_TIME=$1 + +#Constants +TMPDIR="/tmp/cache" + +[ -d "$TMPDIR" ] || mkdir -p "$TMPDIR" + +HASH=$(echo "$CMD" | base64) +CACHE_FILE="$TMPDIR/$HASH" + +if [ -f "$CACHE_FILE" ]; then + CACHE_AGE=$[ $(date +"%s") - $(stat -c "%Y" "$CACHE_FILE") ] + if [ $CACHE_AGE -lt $CACHE_TIME ]; then + cat "$CACHE_FILE" + else + $CMD | tee "$CACHE_FILE" + fi +else + $CMD | tee "$CACHE_FILE" +fi +