Created
April 21, 2024 11:13
-
-
Save Jayman2000/f8e1d010401c0f19125729546fac199b to your computer and use it in GitHub Desktop.
Determine how many files in a repo use LF/CRLF line endings.
This file contains 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 | |
# SPDX-FileNotice: 🅭🄍1.0 This file is dedicated to the public domain using the CC0 1.0 Universal Public Domain Dedication <https://creativecommons.org/publicdomain/zero/1.0/>. | |
# SPDX-FileContributor: Jason Yundt <jason@jasonyundt.email> (2024) | |
set -o errexit -o nounset -o pipefail | |
file_listing="$(git ls-files --eol)" | |
function echo_file_listing { | |
printf "%s\n" "$file_listing" | |
} | |
lf_files="$(echo_file_listing | grep --perl-regexp '^i/lf' | wc --lines)" | |
crlf_files="$(echo_file_listing | grep --perl-regexp '^i/crlf' | wc --lines)" | |
total_files="$(echo_file_listing | wc --lines)" | |
function calculate_percentage { | |
bc <<< "scale=2; $*/$total_files * 100" | |
} | |
printf \ | |
"Total number of files that use LF line endings: %'d (%g%%)\n" \ | |
"$lf_files" \ | |
"$(calculate_percentage "$lf_files")" | |
printf \ | |
"Total number of files that use CRLF line endings: %'d (%g%%)\n" \ | |
"$crlf_files" \ | |
"$(calculate_percentage "$crlf_files")" | |
printf \ | |
"Total number of files: %'d\n" \ | |
"$total_files" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment