Last active
November 26, 2020 10:14
-
-
Save giordanocardillo/d21234ba6ee5fb98cf8cd0c72dcfa682 to your computer and use it in GitHub Desktop.
Bash Spinner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/bin/sh | |
spinner=(" " "1 " "10 " "101 " " 010" " 01" " 0") | |
spinner_length=${#spinner[0]} | |
function spin() { | |
tput cuf "$spinner_length" | |
while [ 1 ]; do | |
for i in "${spinner[@]}"; do | |
tput cub "$spinner_length" | |
tput ech "$spinner_length" | |
printf "%s" "$i" | |
sleep 0.1 | |
done | |
done | |
} | |
function start_spinner() { | |
tput civis | |
spin & | |
spinner_pid=$! | |
} | |
function stop_spinner() { | |
tput cnorm | |
kill -9 $spinner_pid >/dev/null 2>&1 | |
tput cub "$spinner_length" | |
tput ech "$spinner_length" | |
} | |
trap stop_spinner $(seq 0 15) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment