Created
June 21, 2017 10:45
-
-
Save damekr/d6e26dfa61787bb2aea0e8771dc2f1e9 to your computer and use it in GitHub Desktop.
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
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