progress.sh - randomcrap - random crap programs of varying quality
(HTM) git clone git://git.codemadness.org/randomcrap
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
progress.sh (586B)
---
1 #!/bin/sh
2 # Progress indicator script. Pass the total amount of lines (known beforehand)
3 # as argument. Pass lines as input to stdin. Writes progress status to stderr.
4 # Alternative: pv -s total -l
5
6 total="$(($1 + 0))" # convert int
7 if test "${total}" -le 0 -o "$1" != "${total}"; then
8 echo "usage: $0 <total>" >&2
9 exit 1
10 fi
11
12 LC_ALL=C awk -v "total=${total}" '
13 {
14 counter++;
15 percent = (counter * 100) / total;
16 printf("\033[K") > "/dev/stderr";
17 print $0;
18 printf("[%s/%s] %.0f%%\r", counter, total, percent) > "/dev/stderr";
19 fflush();
20 }
21 END {
22 printf("\033[K") > "/dev/stderr";
23 }'