Skip to content

Instantly share code, notes, and snippets.

@rajohns08
Last active August 29, 2015 13:57
Show Gist options
  • Save rajohns08/9701682 to your computer and use it in GitHub Desktop.
Save rajohns08/9701682 to your computer and use it in GitHub Desktop.
showLoading bash function
doSomeTask() {
// make build or some other long task
}
showLoading() {
mypid=$!
loadingText=$1
echo -ne "$loadingText\r"
while kill -0 $mypid 2>/dev/null; do
echo -ne "$loadingText.\r"
sleep 0.5
echo -ne "$loadingText..\r"
sleep 0.5
echo -ne "$loadingText...\r"
sleep 0.5
echo -ne "\r\033[K"
echo -ne "$loadingText\r"
sleep 0.5
done
echo "$loadingText...FINISHED"
}
doSomeTask & showLoading "DOING SOME TASK"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment