Created
August 29, 2025 18:16
-
-
Save AlexHedley/e1297c60e03fb511d5cee5dc9f17533b to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env bash | |
| BATCHSIZE=1 | |
| progress-bar() { | |
| local current=$1 | |
| local len=$2 | |
| local bar_char='|' | |
| local empty_char=' ' | |
| local length=50 | |
| local perc_done=$((current * 100 / len)) | |
| local num_bars=$((perc_done * length / 100)) | |
| local i | |
| local s='[' | |
| for ((i = 0; i < num_bars; i++)); do | |
| s+=$bar_char | |
| done | |
| for ((i = num_bars; i < length; i++)); do | |
| s+=$empty_char | |
| done | |
| s+=']' | |
| echo -ne "$s $current/$len ($perc_done%)\r" | |
| } | |
| process-files() { | |
| local files=("$@") | |
| sleep .01 | |
| } | |
| shopt -s globstar nullglob | |
| echo 'finding files' | |
| files=(./**/*cache) | |
| len=${#files[@]} | |
| echo "found $len files" | |
| for ((i = 0; i < len; i += BATCHSIZE)); do | |
| progress-bar "$((i+1))" "$len" | |
| process-files "${files[@]:i:BATCHSIZE}" | |
| done | |
| progress-bar "$len" "$len" | |
| echo |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
code/2025-08-21-progress-bar/progress-bar
https://github.com/bahamas10/ysap/blob/574c31656361c675ad7a18839ea1612218fc0be4/code/2025-08-21-progress-bar/progress-bar
- https://www.youtube.com/embed/U4CzyBXyOms?si=8EOJbEPcHQ4XiKc3
<iframe width="560" height="315" src="https://www.youtube.com/embed/U4CzyBXyOms?si=8EOJbEPcHQ4XiKc3" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>