Menu

[f1bb48]: / tools / formatsource.sh  Maximize  Restore  History

Download this file

39 lines (30 with data), 1.2 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
#!/bin/bash
# This file is to be run from a bash script under unix/linux/macOS
# for windows 10 and up, WSL needs to be installed
SP=""
RE=""
REGEXT=".*\.\(php\|inc\|css\|md\|js\|sql\)$"
if [[ $(uname) == "Darwin" ]]; then
# Needed for macOS X
SP=" " # Needed for portability with sed
RE="-E"
REGEXT=".*\.(php|inc|css|md|js|sql)$" # no escaping regex parts
fi
pushd() { builtin pushd $1 > /dev/null; }
popd() { builtin popd $1 > /dev/null; }
pushd ..
echo make line endings standard
#echo excluding hidden files
find ${RE} . -type f -not -path '*/\.*' -regex ${REGEXT} \
-exec bash -c "LC_CTYPE=C LANG=C sed -i${SP}'.bak' \"s/$(printf '\r')//g\" {}" \;
echo replace tab char with 4 spaces in every file from here
find ${RE} . -type f -not -path '*/\.*' -regex ${REGEXT} \
-exec bash -c "LC_CTYPE=C LANG=C sed -i${SP}'.bak' -e \"s/$(printf '\t')/ /g\" {}" \;
echo replace trailing spaces
find ${RE} . -type f -not -path '*/\.*' -regex ${REGEXT} \
-exec bash -c "LC_CTYPE=C LANG=C sed -i${SP}'.bak' -e \"s/ *$//g\" {}" \;
echo remove backup files generated in the process
find ${RE} . -type f -not -path '*/\.*' -regex ${REGEXT} \
-exec test -f {}.bak \; -exec rm {}.bak \;
popd
#eof
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.