diff options
Diffstat (limited to '.scripts/progress')
-rwxr-xr-x | .scripts/progress | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/.scripts/progress b/.scripts/progress new file mode 100755 index 0000000..052c6c2 --- /dev/null +++ b/.scripts/progress @@ -0,0 +1,53 @@ +#!/bin/env bash + +set -e + +percent() { + local p=00$(($1 * 100000 / $2)) + printf -v "$3" %.3f ${p::-3}.${p: -3} +} + +percent "$1" 33000 refresh + +if [ -n "$2" ]; then + pid=$(pgrep "$2") +fi + +percentBar() { + local prct totlen=$((8 * $2)) lastchar barstring blankstring + printf -v prct %.2f "$1" + ((prct = 10#${prct/./} * totlen / 10000, prct % 8)) && + printf -v lastchar '\\U258%X' $((16 - prct % 8)) || + lastchar='' + printf -v barstring '%*s' $((prct / 8)) '' + printf -v barstring '%b' "${barstring// /\\U2588}$lastchar" + printf -v blankstring '%*s' $(((totlen - prct) / 8)) '' + printf -v "$3" '%s%s' "$barstring" "$blankstring" +} + +clear +for i in {0..10000..33} 10000; do + if [ -n "$2" ]; then + if [ ! -d "/proc/$pid" ]; then + percentBar 100 $((COLUMNS - 9)) bar + printf '\r|%s|%6.2f%%' "$bar" 100 + exit 0 + fi + fi + + i=0$i + printf -v p %0.2f ${i::-2}.${i: -2} + percentBar $p $((COLUMNS - 9)) bar + printf '\r|%s|%6.2f%%' "$bar" $p + read -srt $refresh _ && break # console sleep avoiding fork +done + +while true; do + if [ -n "$2" ]; then + if [ ! -d "/proc/$pid" ]; then + break + fi + fi +done + +exit 0 |