Created
July 6, 2015 14:58
-
-
Save rotty3000/066111359fdbb1c76592 to your computer and use it in GitHub Desktop.
bash: spin while process completes in the background
This file contains hidden or 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 | |
spin() { | |
local s=("|" "/" "-" '\x5C') | |
local i=0 | |
while kill -0 $1 2> /dev/null; do | |
echo -en "[${s[$i]}]"\\r | |
i=$(( $i == 3 ? 0 : $i + 1 )) | |
sleep .1 | |
done | |
} | |
## Example usage | |
# Execute a command in a subshell with output suppressed (maybe piped to file) | |
(COMMAND > /dev/null 2>&1)& | |
# wait for it with a spinner | |
spin $! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment