-
Notifications
You must be signed in to change notification settings - Fork 1
/
progbar
executable file
·45 lines (37 loc) · 1.09 KB
/
progbar
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
vblocks=(' ' ▁ ▂ ▃ ▄ ▅ ▆ ▇ █)
blocks=(" " ▏ ▎ ▍ ▌ ▋ ▊ ▉ █)
graph() {
local amount=$(( $1 * 1000 ))
local max=$(( $2 ))
local y=$((amount / max * 9 / 1000))
if test "-v" = "$3"; then
printf "${vblocks[$y]}"
elif test "-vh" = "$3"; then
for i in $(seq 1 $y); do
printf "${vblocks[$i]}"
done
else
charWidth="$3"
if test -z "$charWidth"; then charWidth="$(tput cols)"; fi
width=$(( charWidth * 9 ))
steps=$((amount / max * width / 1000))
chars=$((steps/9))
lastBlock=$((steps%9))
test $chars -gt 0 && printf "%$((chars))s" 'x' | sed 's/[x ]/▉/g'
if test $lastBlock -gt 0; then
printf "${blocks[$lastBlock]}"
chars=$((chars + 1))
fi
printf "%$((charWidth - chars + 1))s" ']'
fi
}
if test "-" = "$1"; then
while read one two three; do
if test -z "$two"; then two="$2"; fi
if test -z "$three"; then three="$3"; fi
graph "$one" "$two" "$three"
done
else
graph "$@"
fi