Skip to content

Instantly share code, notes, and snippets.

@marcom04
Created September 28, 2016 14:09
Show Gist options
  • Save marcom04/f944b2e40d32035e42cdaf928b7a9502 to your computer and use it in GitHub Desktop.
Save marcom04/f944b2e40d32035e42cdaf928b7a9502 to your computer and use it in GitHub Desktop.
Simple spinner for Bash
#!/bin/bash
spinner()
{
local phrase="Doing stuff..."
local pid=$1
local delay=0.5 # Adjust spinner speed
local spinstr='|/-\' # Spinner sequence
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " %s [%c] " "$phrase" "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
printf "\r"
sleep $delay
done
printf "\n" # remove this if you want to delete "phrase" when action is complete
printf "\r"
}
(
# ... perform action here ...
sleep 10
) &
spinner $!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment