file_list=$(find src \
! -path "path/to/exclude/*" \
-type f \( -name "*.cpp" -o -name "*.h" \))
length=$(wc -w <<< "$file_list")
echo Running clang-tidy on $length files
echo "$file_list" |
parallel --bar "clang-tidy-19 {}" \
2> >(
perl -pe 'BEGIN{$/="\r";$|=1};s/\r/\n/g' |
grep '%' |
perl -pe 'BEGIN{$|=1}s/\e\[[0-9;]*[a-zA-Z]//g' |
perl -pe "BEGIN{\$length=$length;$|=1} s|(\d+)% (\d+):(\d+)=([\ds]+)\d+=[\ds]+ (\S+).*|\$1% (\$2/\$length) -- \$5|"\$3|" |
perl -ne '$s{$_}++ or print')
The raw output from --bar looks something like this:
# 0 sec src/tuner/Utilities.h
3.65853658536585
[7m3% 3:7[0m9=0s src/tuner/Utilities.h [0m
(With escape sequences to print the progress bar.)
The successive commands processing that output perform the following transformations:
- Transform carriage returns into newlines.
- Find lines containing percentage output.
- Strip out escape sequences.
- Perform a regex replacement to extract and format the number of files processed, the completion percentage, and the name of the file being processed. It also includes the total number of files to be processed via a shell variable.
- Print unique lines.
The BEGIN{$|=1} on all but the last perl invocation are necessary to ensure output gets flushed immediately.
The p option will run perl on each line of input and print the result. The n option runs on each line of input put does not automatically print. The e option provides the script as a CLI argument.