Skip to content

Instantly share code, notes, and snippets.

@eyecatchup
Created June 10, 2015 20:26
Show Gist options
  • Save eyecatchup/c74cbb6f8cea6cb228bf to your computer and use it in GitHub Desktop.
Save eyecatchup/c74cbb6f8cea6cb228bf to your computer and use it in GitHub Desktop.
Bash-style progress bar (/w elapsed time) to show while long-running sub-processes being called.
#!/bin/bash
# Bash-style progress bar (/w elapsed time) to show while long-running sub-processes being called.
# Copyright: 2015, Stephan Schmitz <[email protected]>
# License: MIT
# 1. Paste the `progress` function in your bash script.
function progress () {
s=0.5;
f=0.25;
echo -ne "\r\n";
while true; do
sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[ ] Elapsed: ${s} secs." \
&& sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[> ] Elapsed: ${s} secs." \
&& sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[--> ] Elapsed: ${s} secs." \
&& sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[---> ] Elapsed: ${s} secs." \
&& sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[----> ] Elapsed: ${s} secs." \
&& sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[-----> ] Elapsed: ${s} secs." \
&& sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[------> ] Elapsed: ${s} secs." \
&& sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[-------> ] Elapsed: ${s} secs." \
&& sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[--------> ] Elapsed: ${s} secs." \
&& sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[---------> ] Elapsed: ${s} secs." \
&& sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[----------> ] Elapsed: ${s} secs." \
&& sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[-----------> ] Elapsed: ${s} secs.";
sleep $f && s=`echo ${s} + ${f} + ${f} | bc` && echo -ne "\r\t[------------>] Elapsed: ${s} secs.";
done;
}
# 2. Then, somewhere in your script, wrap any long running process call as follows:
while true; do progress; done &
sleep 20; # or, whatever
kill $!; trap 'kill $!' SIGTERM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment