#!/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