Created
May 13, 2016 11:49
-
-
Save laubstein/aa12a8a9537fa786bf172f170a855aa3 to your computer and use it in GitHub Desktop.
Progressos em bash
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 | |
# from: http://stackoverflow.com/a/12500894 | |
PROGRESS_COUNT=0 | |
PROGRESS_TOTAL=100 | |
PROGRESS_START=`date +%s` | |
while [ $PROGRESS_COUNT -lt $PROGRESS_TOTAL ] | |
do | |
# the code | |
sleep 0.5 | |
PROGRESS_CUR=`date +%s` | |
PROGRESS_COUNT=$(( $PROGRESS_COUNT + 1 )) | |
PROGRESS_RUNTIME=$(( $PROGRESS_CUR-$PROGRESS_START )) | |
PROGRESS_ESTREMAIN=$(( ($PROGRESS_RUNTIME * $PROGRESS_TOTAL / $PROGRESS_COUNT)-$PROGRESS_RUNTIME )) | |
printf "\rHello progress! %d.%d%% done ($PROGRESS_COUNT of $PROGRESS_TOTAL) - est. %d:%0.2d \e[K" $(( $PROGRESS_COUNT*100/$PROGRESS_TOTAL )) $(( ($PROGRESS_COUNT*1000/$PROGRESS_TOTAL)%10)) $(( $PROGRESS_ESTREMAIN/60 )) $(( $PROGRESS_ESTREMAIN%60 )) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment