#! /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=$(($COLUMNS/20))

BAR_LENGTH=$(($(($COLUMNS))-$((2*$LEFT))-2))
DOT=$(($BAR_LENGTH/1))
PERCENT=$(($1*$DOT/100))


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

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

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

echo "|"
#echo "12345678911234567892123456789312345678941234567895123456789612345678971234567898"


