Skip to content

Instantly share code, notes, and snippets.

@AlexHedley
Created August 29, 2025 18:16
Show Gist options
  • Select an option

  • Save AlexHedley/e1297c60e03fb511d5cee5dc9f17533b to your computer and use it in GitHub Desktop.

Select an option

Save AlexHedley/e1297c60e03fb511d5cee5dc9f17533b to your computer and use it in GitHub Desktop.
#!/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
@AlexHedley
Copy link
Author

AlexHedley commented Aug 29, 2025

code/2025-08-21-progress-bar/progress-bar
https://github.com/bahamas10/ysap/blob/574c31656361c675ad7a18839ea1612218fc0be4/code/2025-08-21-progress-bar/progress-bar

<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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment