-
-
Save basicfeatures/c5b1f8952aafcef865977e383985ac58 to your computer and use it in GitHub Desktop.
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 zsh | |
# CLEANS UP TEXT FILES | |
setopt nullglob | |
setopt extendedglob | |
# Skip vendors | |
for file in (^vendor/)#*(.); do | |
# Match text-files | |
if file -b $file | grep -q "text"; then | |
# Read file into a variable | |
raw=$(<$file) | |
# Remove CR+LF (^M) | |
raw=${raw//$'\r'} | |
# Remove trailing whitespace | |
raw=${raw//$'[ \t]##\n'/$'\n'} | |
# Compress two or more consecutive blank lines | |
raw=${raw//$'\n'(#c3,)/$'\n\n'} | |
# Save result while ensuring newline at EOF | |
printf "%s\n" $raw > $file | |
echo $file | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment