From 5ccfca750eb5f160149b4ff908ec0b7a8f18c32e Mon Sep 17 00:00:00 2001 From: Kroese Date: Sat, 4 May 2024 15:54:43 +0200 Subject: [PATCH] Update progress.sh --- src/progress.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/progress.sh b/src/progress.sh index d32e272..be3cba5 100644 --- a/src/progress.sh +++ b/src/progress.sh @@ -12,7 +12,8 @@ escape () { } file="$1" -body=$(escape "$2") +total="$2" +body=$(escape "$3") info="/run/shm/msg.html" if [[ "$body" == *"..." ]]; then @@ -24,7 +25,12 @@ do if [ -s "$file" ]; then bytes=$(du -sb "$file" | cut -f1) if (( bytes > 1000 )); then - size=$(echo "$bytes" | numfmt --to=iec --suffix=B | sed -r 's/([A-Z])/ \1/') + if [ -z "$total" ]; then + size=$(numfmt --to=iec --suffix=B "$bytes" | sed -r 's/([A-Z])/ \1/') + else + size=$(printf '%.1f\n' "$((bytes*100*100/total))e-2") + size="$size%" + fi echo "${body//(\[P\])/($size)}"> "$info" fi fi