create command caching script and added update widget to bar

This commit is contained in:
madmaurice 2015-06-08 08:37:42 +02:00
parent 3540e9adce
commit 8f03791d77
2 changed files with 31 additions and 1 deletions

View file

@ -13,6 +13,7 @@ icon_wifi=$(icon 048)
icon_battery=$(icon 033) icon_battery=$(icon 033)
icon_battery_charging=$(icon 042) icon_battery_charging=$(icon 042)
icon_clock=$(icon 018) icon_clock=$(icon 018)
icon_updates=$(icon 060)
color_service_running="#A0A57E" color_service_running="#A0A57E"
color_service_stopped="#C37561" color_service_stopped="#C37561"
@ -81,6 +82,11 @@ clock() {
echo -n "%{A:I "clock 1061":}$icon_clock $info%{A}" 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() { run_handler() {
while read type param; do while read type param; do
case $type in case $type in
@ -94,7 +100,7 @@ run_handler() {
while true; do while true; do
echo "%{l} $(music) $(services) $(diskspace)%{r}$(wifi) $(battery) $(clock) " echo "%{l} $(music) $(services) $(diskspace)%{r}$(updates) $(wifi) $(battery) $(clock) "
sleep 1 sleep 1
done | lemonbar -g 1366x15 -f "Terminus:size=8","Stlarch:size=6:style=regular" -B "#88000000" | run_handler done | lemonbar -g 1366x15 -f "Terminus:size=8","Stlarch:size=6:style=regular" -B "#88000000" | run_handler

24
scripts/cmdcache.sh Executable file
View file

@ -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