Skip to content

Commit

Permalink
report progress when formatting cpp files
Browse files Browse the repository at this point in the history
  • Loading branch information
expipiplus1 committed Oct 30, 2024
1 parent d6c29a6 commit 4bef384
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions extras/formatting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ cmake_formatting() {
fi
}

track_progress() {
[ -t 1 ] || return

local total=$1
local current=0

while IFS= read -r _; do
((current++)) || :
percent=$((current * 100 / total))
printf '\rProgress: [%-50s] %d%%' "$(printf '#%.0s' $(seq 1 $((percent / 2))))" "$percent"
done
echo
}

cpp_formatting() {
echo "Formatting cpp files..."

Expand All @@ -112,11 +126,11 @@ cpp_formatting() {
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT

printf '%s\n' "${files[@]}" | xargs -P "$(nproc)" -I{} bash -c "
printf '%s\n' "${files[@]}" | xargs --verbose -P "$(nproc)" -I{} bash -c "
mkdir -p \"\$(dirname \"$tmpdir/{}\")\"
diff -u --color=always --label \"{}\" --label \"{}\" \"{}\" <(clang-format \"{}\") > \"$tmpdir/{}\"
diff -u --color=always --label \"{}\" --label \"{}\" \"{}\" <(clang-format \"{}\") > \"$tmpdir/{}\"
:
"
" |& track_progress ${#files[@]}

for file in "${files[@]}"; do
if [ -s "$tmpdir/$file" ]; then
Expand All @@ -125,7 +139,8 @@ cpp_formatting() {
fi
done
else
printf '%s\n' "${files[@]}" | xargs -n1 -P "$(nproc)" clang-format -i
printf '%s\n' "${files[@]}" | xargs -n1 -P "$(nproc)" clang-format -i |&
track_progress ${#files[@]}
fi
}

Expand Down Expand Up @@ -167,8 +182,8 @@ sh_formatting() {
}

cmake_formatting
cpp_formatting
yaml_json_formatting
sh_formatting
cpp_formatting

exit $exit_code

0 comments on commit 4bef384

Please sign in to comment.