Skip to content

Instantly share code, notes, and snippets.

@rotty3000
Created July 6, 2015 14:58
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 rotty3000/066111359fdbb1c76592 to your computer and use it in GitHub Desktop.
Save rotty3000/066111359fdbb1c76592 to your computer and use it in GitHub Desktop.
bash: spin while process completes in the background
#!/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