Skip to content

Instantly share code, notes, and snippets.

@giordanocardillo
Last active November 26, 2020 10:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giordanocardillo/d21234ba6ee5fb98cf8cd0c72dcfa682 to your computer and use it in GitHub Desktop.
Save giordanocardillo/d21234ba6ee5fb98cf8cd0c72dcfa682 to your computer and use it in GitHub Desktop.
Bash Spinner
#/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