forked from AliceO2Group/Run3AnalysisValidation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_spaces.sh
41 lines (37 loc) · 1.24 KB
/
check_spaces.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
#!/bin/bash
# Find tabs and trailing whitespaces in text files
# This directory
DIR_THIS="$(dirname "$(realpath "$0")")"
# Load utilities.
# shellcheck disable=SC1091 # Ignore not following.
source "$DIR_THIS/utilities.sh" || { echo "Error: Failed to load utilities."; exit 1; }
status_tab=0
status_trail=0
# loop over files
while IFS= read -r f; do
# ignore binary files
file -bi "$f" | grep -q "charset=binary" && continue
echo "Scanning file: $f"
# find tabs in file
if grep -q -P "\t" "$f"; then
status_tab=1
MsgErr "Found some tabs in $f:" > /dev/stderr
# print out where the tabs are
#grep -P -n "\t" "$f" > /dev/stderr
awk 'i=index($0, "\t") {printf "%i (col. %i): %s\n", NR, i, $0}' "$f" > /dev/stderr
fi
# find trailing whitespaces in file
if grep -q " $" "$f"; then
status_trail=2
MsgErr "Found some trailing whitespaces in $f:" > /dev/stderr
# print out where the tabs are
grep -n " $" "$f" > /dev/stderr
fi
done < <(find . -type f -not -path "./.git/*")
status=$((status_tab + status_trail))
if [ "$status" -ne 0 ]; then
MsgWarn "Command tips:
- Replace each tab with two spaces: sed -i 's/\\\t/ /g' <files>
- Remove trailing whitespaces: sed -i 's/[[:space:]]*$//' <files>"
fi
exit $status