mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-22 22:34:23 -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}
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue