-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloading.sh
46 lines (36 loc) · 872 Bytes
/
loading.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
#!/bin/bash
# Set background to white
tput setb 7
# Set text color to black
tput setaf 0
# Define spinner characters
spinner=( '⠋' '⠙' '⠹' '⠸' '⠼' '⠴' '⠦' '⠧' '⠇' '⠏' )
# Clean up on script exit
cleanup() {
tput reset
tput cnorm
exit 0
}
trap cleanup EXIT
tput civis
start_time=$(date +%s)
duration=2
i=0
while true; do
current_time=$(date +%s)
elapsed=$((current_time - start_time))
# Calculate progress percentage
progress=$((elapsed * 100 / duration))
if [ $progress -gt 100 ]; then
progress=100
fi
if [ $elapsed -ge $duration ]; then
printf "\rLoading complete! [100%%] \n"
break
fi
# Display spinner with progress percentage
printf "\r[%s] Loading... %d%%" "${spinner[i]}" "$progress"
i=$(( (i+1) % ${#spinner[@]} ))
sleep 0.1
done
cleanup