performance improvements to 'custom', add 'readfile' to shutil and use it

This commit is contained in:
Scott Moser 2011-05-18 12:04:26 -04:00
commit 5b6dcfbf54
2 changed files with 22 additions and 7 deletions

View file

@ -64,4 +64,16 @@ rtrim() {
_RET=${cur}
}
readfile() {
local c="" r="" cr="
"
OIFS="$IFS"; IFS="";
while read c; do
r="$r${cr}$c"
done
IFS=$OIFS
_RET=${r}
return 0
}
# vi: syntax=sh ts=4 noexpandtab

View file

@ -30,15 +30,18 @@ CACHE="$DIR/$PKG.custom"
# Loop over custom scripts
for i in "$DATA/bin/"[0-9]*_*; do
[ -x "$i" ] || continue
script=$(basename "$i")
freq=$(echo "$script" | awk -F_ '{print $1}')
lastrun=$(stat -c %Y "$CACHE.$script") 2>/dev/null || lastrun=0
expiration=$(expr $lastrun + $freq)
script=${script##*/}
freq=${script%%_*}
freq=${freq#0}
[ -r "$CACHE.$script.last" ] && read lastrun "$CACHE.$script.last" ||
lastrun=0
expiration=$(($lastrun+$freq))
if [ $NOW -ge $expiration ]; then
# Update the cache
$i $@ > "$CACHE.$script" 2>/dev/null
"$i" "$@" > "$CACHE.$script" 2>/dev/null
echo "${NOW}" > "$CACHE.$script.last"
fi
output=$(cat "$CACHE.$script")
readfile < "$CACHE.$script"
output="${_RET}"
case "$output" in
*"$ESC{"*)
# User has formatted the colors