Skip to content

Instantly share code, notes, and snippets.

@netmute
Last active September 3, 2015 16:39
Show Gist options
  • Save netmute/308423ea435ff0df53a4 to your computer and use it in GitHub Desktop.
Save netmute/308423ea435ff0df53a4 to your computer and use it in GitHub Desktop.
a simple spinning animation for your shell scripts
#!/usr/bin/env bash
#
# a simple spinning animation for your shell scripts
# prints message in front of spinner
# - argument 1: the message to print
spinner_init() {
printf "$1 "
}
# renders spinner animation once for 0.4 seconds
spinner_spin() {
printf "\b/"
sleep 0.1
printf "\b-"
sleep 0.1
printf "\b\\"
sleep 0.1
printf "\b|"
sleep 0.1
}
# prints message after the spinner
# - argument 1: the message to print
spinner_done() {
printf "\b\b: $1\n"
}
# use it like this
spinner_init "Waiting for demo.txt"
while [ ! -f "./demo.txt" ]; do
spinner_spin
done
spinner_done "found"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment