-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdos2unix.sh
executable file
·52 lines (43 loc) · 957 Bytes
/
dos2unix.sh
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#! /bin/sh
# convert CRLF to LF
# Credits: https://gist.github.com/jappy/2012320
# --------------------
# How to
# --------------------
# 1. Make executable
# chmod +x dos2unix.sh
# 2. Apply
# ./dos2unix.sh filename.txt
# ./dos2UNIX.sh [ab]*.txt
convertFile() {
FILE=$1
if [[ -f $FILE ]]; then
echo "Converting $FILE $(pwd)"
tr -d '\015' < "$FILE" > "tmp.$FILE"
mv "tmp.$FILE" "$FILE"
fi
}
changeEOL() {
for file in *
do
root="${file%.*}"
ext="${file#"$root"}"
if [[ "$ext" =~ ^(\.toml|\.md|\.html|\.js|\.scss|\.css|\.json)$ ]]; then
convertFile $file
fi
done
# Recursively change subdirectories
for d in ./*/ ; do (cd "$d" && changeEOL); done
}
# Recursively all the folders
for d in ./*/ ; do (cd "$d" && changeEOL); done
# Files in root
for file in *
do
convertFile $file
done
# dotfiles in root
for file in .*
do
convertFile $file
done