script/gentree: make cpio subshells fail if cd(1) fails.
[CDN/Mosi.git] / script / lib / progress.sh
1 # Progress library script
2
3 if [ -z "${__progress_sh_loaded}" ]
4 then
5   __progress_sh_loaded=yes
6   
7   # Implement a simple progress indicator
8   # ( i:current i:total i:width -- s:
9   progress() {
10     local time_last
11
12     cur="${1}"
13     all="${2}"
14     width="${3:-78}"
15
16     time="$(date +%s)"
17
18     prcnt="$(printf "%u / %u * 100\n" "${cur}" "${all}" | bc -l 2>/dev/null)"
19     elapsed="$(printf "%u - %u\n" "${time}" "${time_start}" | bc -l 2>/dev/null)"
20     remain="$(printf "( %u - %u ) / ( %u / %u )\n" "${all}" "${cur}" "${cur}" "${elapsed}" | bc -l 2>/dev/null)"
21
22     time_last="${time}"
23
24     printf "%0.2f%% E:%us R:%0.1fs" "${prcnt:-0}" "${elapsed:-0}" "${remain:-0}"
25   }
26 fi