Skip to content

Instantly share code, notes, and snippets.

@damekr
Created June 21, 2017 10:45
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 damekr/d6e26dfa61787bb2aea0e8771dc2f1e9 to your computer and use it in GitHub Desktop.
Save damekr/d6e26dfa61787bb2aea0e8771dc2f1e9 to your computer and use it in GitHub Desktop.
spin()
{
local \
before_msg="$1" \
after_msg="$2"
local spinner
local -a spinners
spinners=(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏)
# hide cursor
tput civis
while true
do
for spinner in "${spinners[@]}"
do
if [[ -f $TMPFILE ]]; then
rm -f $TMPFILE
tput cnorm
return 1
fi
sleep 0.05
printf " $fg[white]$spinner$reset_color $before_msg\r" 2>/dev/null
done
echo "$jobstates" \
| awk '
/[0-9]+=/ {
jobs[++job_count] = $0
}
END {
for (i = 1; i <= job_count; i++) {
print(jobs[i])
}
exit job_count == 0
}' \
| xargs test -z && break
done
if [[ -n $after_msg ]]; then
printf "\033[2K"
printf " $fg_bold[blue]\U2714$reset_color $after_msg\n"
fi 2>/dev/null
# show cursor
tput cnorm || true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment