Advertisement
P22DX

ProgressBar.bash

Jan 21st, 2020
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.98 KB | None | 0 0
  1. #!/data/data/com.termux/files/usr/bin/bash
  2. # Author: Teddy Skarin
  3. # File: ProgressBar.bash
  4. # Date: 21.01.2020
  5. # Last Modified Date: 21.01.2020
  6. # Last Modified By: Cvar1984 <gedzsarjuncomuniti@gmail.com>
  7.  
  8. # 1. Create ProgressBar function
  9. # 1.1 Input is currentState($1) and totalState($2)
  10. function ProgressBar {
  11.     # Process data
  12.     let _progress=(${1}*100/${2}*100)/100
  13.     let _done=(${_progress}*4)/10
  14.     let _left=40-$_done
  15.     # Build progressbar string lengths
  16.     _done=$(printf "%${_done}s")
  17.     _left=$(printf "%${_left}s")
  18.  
  19. # 1.2 Build progressbar strings and print the ProgressBar line
  20. # 1.2.1 Output example:
  21. # 1.2.1.1 Progress : [########################################] 100%
  22. printf "\rProgress : [${_done// /#}${_left// /-}] ${_progress}%%"
  23.  
  24. }
  25.  
  26. # Variables
  27. _start=1
  28.  
  29. # This accounts as the "totalState" variable for the ProgressBar function
  30. _end=100
  31.  
  32. # Proof of concept
  33. for number in $(seq ${_start} ${_end})
  34. do
  35.     sleep 0.1
  36.     ProgressBar ${number} ${_end}
  37. done
  38. printf '\nFinished!\n'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement