Created
June 3, 2019 11:57
-
-
Save gitfib/06ffef5d45283680f4637f35ec2b6bc3 to your computer and use it in GitHub Desktop.
winify and nixify text files (line endings and .txt file extensions)
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 | |
for var in "$@"; do | |
if [[ "$(file --brief -i $var | awk '{print $1}')" == 'text/plain;' && | |
"$(file --brief $var | grep CRLF)" ]]; then | |
dos2unix $var | |
base="$(basename $var)" | |
if [ "${base##*.}" == 'txt' ]; then | |
mv $var "${var%.*}" | |
fi | |
fi | |
done |
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 | |
for var in "$@"; do | |
if [[ "$(file --brief -i $var | awk '{print $1}')" == 'text/plain;' && | |
! "$(file --brief $var | grep CRLF)" ]]; then | |
unix2dos $var | |
base="$(basename $var)" | |
if [ "${base##*.}" != 'txt' ]; then | |
mv $var $var.txt | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment