forked from parallaxinc/spin-standard-library
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencode.sh
More file actions
executable file
·30 lines (24 loc) · 740 Bytes
/
encode.sh
File metadata and controls
executable file
·30 lines (24 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
while read -r line
do
echo $line
ENCODING=$(file "$line" | cut -d':' -f 2)
# Fix encoding
if [[ $ENCODING == *"ISO-8859"* ]] ; then
echo "ISO-8859"
iconv -f iso-8859-1 -t utf-8 "$line" > "$line.tmp"
mv "$line.tmp" "$line"
elif [[ $ENCODING == *"UTF-16"* ]] ; then
echo "UTF-16"
iconv -f utf-16 -t utf-8 "$line" > "$line.tmp"
mv "$line.tmp" "$line"
fi
# Fix line endings
if [[ $ENCODING == *"CR line terminators"* ]] ; then
mac2unix "$line"
elif [[ $ENCODING == *"CRLF line terminators"* ]] ; then
dos2unix "$line"
fi
# Remove trailing whitespace
sed -i "$line" -e 's/[ \t]*$//g'
done < <(find . -name \*.spin)