Skip to content

Commit 9bdad23

Browse files
committed
report progress when formatting cpp files
1 parent d6c29a6 commit 9bdad23

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

extras/formatting.sh

+18-5
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ cmake_formatting() {
102102
fi
103103
}
104104

105+
track_progress() {
106+
local total=$1
107+
local current=0
108+
109+
while IFS= read -r _; do
110+
((current++)) || :
111+
percent=$((current * 100 / total))
112+
printf '\rProgress: [%-50s] %d%%' "$(printf '#%.0s' $(seq 1 $((percent / 2))))" "$percent"
113+
done
114+
echo
115+
}
116+
105117
cpp_formatting() {
106118
echo "Formatting cpp files..."
107119

@@ -112,11 +124,11 @@ cpp_formatting() {
112124
tmpdir=$(mktemp -d)
113125
trap 'rm -rf "$tmpdir"' EXIT
114126

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

121133
for file in "${files[@]}"; do
122134
if [ -s "$tmpdir/$file" ]; then
@@ -125,7 +137,8 @@ cpp_formatting() {
125137
fi
126138
done
127139
else
128-
printf '%s\n' "${files[@]}" | xargs -n1 -P "$(nproc)" clang-format -i
140+
printf '%s\n' "${files[@]}" | xargs -n1 -P "$(nproc)" clang-format -i |&
141+
track_progress ${#files[@]}
129142
fi
130143
}
131144

@@ -167,8 +180,8 @@ sh_formatting() {
167180
}
168181

169182
cmake_formatting
170-
cpp_formatting
171183
yaml_json_formatting
172184
sh_formatting
185+
cpp_formatting
173186

174187
exit $exit_code

0 commit comments

Comments
 (0)