mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-23 06:36:17 -07:00
performance improvements to 'custom', add 'readfile' to shutil and use it
This commit is contained in:
parent
b77cfafc8c
commit
5b6dcfbf54
2 changed files with 22 additions and 7 deletions
|
@ -64,4 +64,16 @@ rtrim() {
|
||||||
_RET=${cur}
|
_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
|
# vi: syntax=sh ts=4 noexpandtab
|
||||||
|
|
|
@ -30,15 +30,18 @@ CACHE="$DIR/$PKG.custom"
|
||||||
# Loop over custom scripts
|
# Loop over custom scripts
|
||||||
for i in "$DATA/bin/"[0-9]*_*; do
|
for i in "$DATA/bin/"[0-9]*_*; do
|
||||||
[ -x "$i" ] || continue
|
[ -x "$i" ] || continue
|
||||||
script=$(basename "$i")
|
script=${script##*/}
|
||||||
freq=$(echo "$script" | awk -F_ '{print $1}')
|
freq=${script%%_*}
|
||||||
lastrun=$(stat -c %Y "$CACHE.$script") 2>/dev/null || lastrun=0
|
freq=${freq#0}
|
||||||
expiration=$(expr $lastrun + $freq)
|
[ -r "$CACHE.$script.last" ] && read lastrun "$CACHE.$script.last" ||
|
||||||
|
lastrun=0
|
||||||
|
expiration=$(($lastrun+$freq))
|
||||||
if [ $NOW -ge $expiration ]; then
|
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
|
fi
|
||||||
output=$(cat "$CACHE.$script")
|
readfile < "$CACHE.$script"
|
||||||
|
output="${_RET}"
|
||||||
case "$output" in
|
case "$output" in
|
||||||
*"$ESC{"*)
|
*"$ESC{"*)
|
||||||
# User has formatted the colors
|
# User has formatted the colors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue