fix: Only display non-zero percentage (#1087)

This commit is contained in:
Kroese 2025-10-19 17:32:25 +02:00 committed by GitHub
parent 221b0242fa
commit 5577178eeb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,27 +21,23 @@ if [[ "$body" == *"..." ]]; then
body="<p class=\"loading\">${body::-3}</p>"
fi
cluster=$(stat -f "$path" | grep -m 1 "^Block size:" | cut -d':' -f2 | tail -c+2 | cut -d' ' -f1)
total=$(( ( ( total + cluster / 2 ) / cluster ) * cluster ))
[ -z "$total" ] && total="4096"
while true
do
if [ ! -s "$path" ] && [ ! -d "$path" ]; then
bytes="0"
else
bytes=$(du -sB 1 "$path" | cut -f1)
bytes=$(du -sb "$path" | cut -f1)
fi
if (( bytes > cluster )); then
if (( bytes > 4096 )); then
if [ -z "$total" ] || [[ "$total" == "0" ]] || [ "$bytes" -gt "$total" ]; then
size=$(numfmt --to=iec --suffix=B "$bytes" | sed -r 's/([A-Z])/ \1/')
else
size="$(echo "$bytes" "$total" | awk '{printf "%.1f", $1 * 100 / $2}')"
size="$size%"
fi
echo "${body//(\[P\])/($size)}"> "$info"
[[ "$size" != "0.0%" ]] && echo "${body//(\[P\])/($size)}"> "$info"
fi
sleep 1 & wait $!