summaryrefslogtreecommitdiff
path: root/etc/functions/progress
blob: f3e439d42c218394a1d528fdf587c369701b0b1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## vim:ft=zsh
## progress - draw a simple progress bar
## Written 2008 by Daniel Friesel <derf@derf.homelinux.org>
## Usage: progress <current> <max> [left description] [right discription]

typeset -i current=$1
typeset -i max=$2
typeset desc=$3
typeset desc2=$4
typeset output=''
typeset currentper=$(( (current*100)/max ))
typeset c a
function item {
	typeset j
	for j in {0..$1}; {
		(( j > 0 )) && output+=$2
	}
}
c=$(( currentper/5 ))
a=$(( 20-c ))
output+="$desc ["
item $c '='
item $a ' '
output+="] $currentper% $desc2"
echo -ne "\r\e[2K"
echo -ne $output