diff --git a/common.nix b/common.nix index 57e74b9..8d5ef40 100644 --- a/common.nix +++ b/common.nix @@ -29,6 +29,7 @@ let { blocks='########################################' drawn= + total=0 while read -r tag rest; do case "$tag" in A) copy_id=$rest ;; @@ -36,6 +37,7 @@ let printf '%s\n' "$rest" >&2 ;; P) set -- $rest [ "$1" = "''${copy_id:-}" ] && [ "''${3:-0}" -gt 0 ] || continue + total=$3 pct=$(( $2 * 100 / $3 )) printf '\r[%-40s] %3d%% %d/%d paths' \ "''${blocks:0:$(( pct * 40 / 100 ))}" "$pct" "$2" "$3" @@ -45,7 +47,14 @@ let # `if`, not `[ … ] && …`: with nothing to copy the bar never draws, and a # bare test as the last statement would exit 1 and break the caller's # && chain. A real copy failure still surfaces via the caller's pipefail. - if [ -n "$drawn" ]; then printf '\n'; fi + # + # nix stops emitting type-105 results once the last path lands, so the + # bar's last live frame is always one path short. Redraw it full on EOF. + # An error would have cleared $drawn via the M branch first, so this only + # fires on a copy that actually finished. + if [ -n "$drawn" ]; then + printf '\r[%-40s] 100%% %d/%d paths\n' "$blocks" "$total" "$total" + fi } '';