Unverified Commit 82b558d5 authored by Kroese's avatar Kroese Committed by GitHub
Browse files

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

parent 6e85f5df
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -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 $!