Skip to content

Instantly share code, notes, and snippets.

@laubstein
Created May 13, 2016 11:49
Show Gist options
  • Save laubstein/aa12a8a9537fa786bf172f170a855aa3 to your computer and use it in GitHub Desktop.
Save laubstein/aa12a8a9537fa786bf172f170a855aa3 to your computer and use it in GitHub Desktop.
Progressos em bash
#!/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