Created
March 14, 2014 20:07
-
-
Save MarcosBL/9555743 to your computer and use it in GitHub Desktop.
Bash progress bar
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
| show_prog_bar() { | |
| local c="$1" # Character to use to draw progress bar | |
| local v=$2 # Percentage 0<= value <=100 | |
| local t=$3 # Text before | |
| local pbl=50 # Progress bar length in characters | |
| local r=`expr 100 / $pbl` # Ratio between percentage value and progress bar length | |
| local p="$v%" # Percentage value to display in the middle of progress bar | |
| local l=${#p} # Length of string to display | |
| local pbs="" # Progress bar string | |
| local k=`expr \( $pbl - $l \) / 2` # Position where to substitute in progress bar string | |
| local n1=`expr $v / $r` | |
| local n2=`expr $pbl - $n1` | |
| for (( i=0; i<$pbl; i++ )); do | |
| pbs="${pbs}${c}" | |
| done | |
| pbs=`echo "$pbs" | sed 's/^\(.\{'"${k}"'\}\)\(.\{'"${l}"'\}\)\(.*$\)/\1'"${p}"'\3/'` | |
| printf "\r\e[0m${t} \e[1;42m%s\e[1;41m%s\e[0m%s" "${pbs:0:$n1}" "${pbs:$n1:$n2}" "${c}" | |
| } | |
| show_prog_bar " " 65 "Progreso de conversión: " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment