-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNT2Linux.sh
More file actions
61 lines (49 loc) Β· 1.44 KB
/
NT2Linux.sh
File metadata and controls
61 lines (49 loc) Β· 1.44 KB
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
53
54
55
56
57
58
59
60
61
#!/bin/bash
# UltimateFileFixer/NT2Linux - Fix allthe little annoyances in your files
# Powered by CorgiMasterEpic πβ¨
set -e
# Default mode: NT β Linux
MODE="nt2linux"
# Check for --linux2nt flag
if [ "$1" == "--linux2nt" ]; then
MODE="linux2nt"
shift
fi
if [ $# -lt 1 ]; then
echo "Usage: $0 [--linux2nt] [File(s)]"
exit 1
fi
for file in "$@"; do
if [ ! -f "$file" ]; then
echo "Skipping: $file (not a file)"
continue
fi
echo "π§ Fixing $file..."
# 1. Line endings
if [ "$MODE" == "nt2linux" ]; then
sed -i 's/\r$//' "$file"
echo "βοΈ CRLF β LF done."
else
sed -i 's/$/\r/' "$file"
echo "βοΈ LF β CRLF done."
fi
# 2. Remove trailing whitespace
sed -i 's/[ \t]*$//' "$file"
echo "π§Ή Trailing whitespace cleared."
# 3. Normalize tabs β 4 spaces
expand -t 4 "$file" > tmp && mv tmp "$file"
echo "π Tabs normalized to 4 spaces."
# 4. Ensure newline at end
sed -i -e '$a\' "$file"
echo "β Newline at end ensured."
# 5. Remove non-printable characters
tr -cd '\11\12\15\40-\176' < "$file" > tmp && mv tmp "$file"
echo "π§Ή Non-printable characters removed."
# 6. Make script executable if it starts with shebang
if head -n 1 "$file" | grep -q "^#!"; then
chmod +x "$file"
echo "π Script is now executable."
fi
# Fun celebration
echo -e "πΎ $file is now pure, clean, and ready for Linux/Windows! Thanks for using NT2Linux! πΎ\n"
done