-
Notifications
You must be signed in to change notification settings - Fork 0
/
spinner_v1.sh
73 lines (58 loc) · 1.11 KB
/
spinner_v1.sh
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
# Created by Pavel Raykov aka 'rabbit' / 2016-01-26 (c)
# $Id$
# Description:
#
# Simple spinner while waiting for
# a completion of any running background task
SPIN_DELAY=0.05
TIMEOUT=30
pos=0
char=">"
dots_a="........"
dots_b=""
dots_count="${#dots_a}"
limit=$[dots_count*2]
dot="${dots_a:0:1}"
printSpinner()
{
local repeat="$( LC_ALL=C LC_NUMERIC=C printf "%.0f\n" `echo "1 / $SPIN_DELAY" | bc -ql` )"
if which bc &>/dev/null; then
while [ "$repeat" -gt 0 ]; do
printf "["
printf "%s" "$dots_b"
printf "%c" "$char"
printf "%s" "$dots_a"
printf "]"
sleep $SPIN_DELAY
printf "\b\b\b\b\b\b\b\b\b\b\b"
if [ $pos -lt $dots_count ]; then
char=">"
dots_a="${dots_a%?}"
dots_b+="$dot"
let pos++
elif [ $pos -lt $limit ]; then
char="<"
dots_b="${dots_b%?}"
dots_a+="$dot"
let pos++
else
char='>'
pos=0
fi
let --repeat
done
else
# Use sleep(1) if `bc' doesn't installed
sleep 1
fi
}
printf "Please wait..\t"
n=0
while [ $n -lt $TIMEOUT ]; do
printSpinner
let n++
done
echo
exit 0
# EOF