Created
September 28, 2016 14:09
-
-
Save marcom04/f944b2e40d32035e42cdaf928b7a9502 to your computer and use it in GitHub Desktop.
Simple spinner for Bash
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/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