#! /bin/bash
# (c) 2005 Sune Vuorela <pusling@pusling.com>
# Version 0.9
#
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <pusling@pusling.com> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you
# think this stuff is worth it, you can buy me a beer in return.
#   Sune Vuorela
# ----------------------------------------------------------------------------
#
# Original beerware license is due to Poul-Henning Kamp.

if [ -z $1 ]; then
	echo "Remember to set value for the progress bar"
	echo "progressbar percent [bar-char] [empty-char]"
	exit
fi

if [ -z $2 ]; then
	SOME="="
else
	SOME=${2:0:1}
fi

if [ -z $3 ]; then
	EMPTY=" "
else
	EMPTY=${3:0:1}
fi

COLUMNS=80


LEFT=$(echo  "scale=10;$COLUMNS*100/20" | bc)
BAR_LENGTH=$(echo "scale=10;$COLUMNS*100-2*$LEFT-200"|bc)
DOT=$(echo "scale=10;$BAR_LENGTH/100" | bc)
PERCENT=$(echo "scale=10;$1*$DOT"|bc)

LEFT=`./round.sh $LEFT`
BAR_LENGTH=`./round.sh $BAR_LENGTH`
DOT=`./round.sh $DOT`
PERCENT=`./round.sh $PERCENT`


NUMCHARS=0
for ((i=0;$i<$LEFT;i=$i+100))
do
echo -n " "
done
echo -n "|"

for ((i=0;$i<$PERCENT;i=$i+100))
do
echo -n "$SOME"
NUMCHARS=$((NUMCHARS+1))
done

for ((i=$PERCENT;i<$BAR_LENGTH && $NUMCHARS<$((BAR_LENGTH/100));i=$i+100))
do
echo -n "$EMPTY"
NUMCHARS=$((NUMCHARS+1))
done

echo "|"

