Created
June 10, 2015 20:26
-
-
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.
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
| #!/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