From 399243886e1712395514674d62312024d2624b47 Mon Sep 17 00:00:00 2001 From: Kroese Date: Sun, 19 Oct 2025 09:40:45 +0200 Subject: [PATCH] feat: Show directory size (#1083) --- src/progress.sh | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/progress.sh b/src/progress.sh index 6f47329..e3b37d2 100644 --- a/src/progress.sh +++ b/src/progress.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash set -Eeuo pipefail +info="/run/shm/msg.html" + escape () { local s s=${1//&/\&} @@ -14,25 +16,30 @@ escape () { file="$1" total="$2" body=$(escape "$3") -info="/run/shm/msg.html" if [[ "$body" == *"..." ]]; then - body="

${body/.../}

" + body="

${body::-3}

" fi while true do - if [ -s "$file" ]; then + + if [ ! -s "$file" ] && [ ! -d "$file" ]; then + bytes="0" + else bytes=$(du -sb "$file" | cut -f1) - if (( bytes > 1000 )); 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" - fi fi + + if (( bytes > 1000 )); 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" + fi + sleep 1 & wait $! + done