Commit | Line | Data |
---|---|---|
c35dfd6a SK |
1 | #! /bin/sh |
2 | ||
3 | BOM='^\xef\xbb\xbf' | |
4 | ||
5 | case "`uname`" in | |
6 | Darwin) | |
7 | _sed=gsed; | |
8 | _grep=ggrep;; | |
9 | *) | |
10 | _sed=sed; | |
11 | _grep=grep;; | |
12 | esac | |
13 | ||
14 | case "$1" in | |
15 | '') _dir=.;; | |
16 | *) _dir="$1";; | |
17 | esac | |
18 | ||
19 | _find() { | |
20 | _pattern="$1" | |
21 | LC_ALL=C "$_grep" \ | |
22 | --color=never \ | |
23 | -rIcP \ | |
24 | --exclude-dir=.git \ | |
25 | "$_pattern" "$_dir" \ | |
26 | | awk -F: '$2 {print $1}' | |
27 | } | |
28 | ||
29 | _delete() { | |
30 | _pattern="$1" | |
31 | while read _file | |
32 | do | |
33 | tmp="`mktemp`" | |
34 | LC_ALL=C "$_sed" "s/$_pattern//" "$_file" > "$tmp" | |
35 | mv "$tmp" "$_file" | |
36 | done | |
37 | } | |
38 | ||
39 | ||
40 | echo 'BOM:' | |
41 | echo '----' | |
42 | _find "$BOM" | |
43 | _find "$BOM" | _delete "$BOM" | |
44 | ||
45 | echo '' | |
46 | ||
47 | echo 'Trailing carriage return:' | |
48 | echo '-------------------------' | |
49 | _find '\r' | |
50 | _find '\r' | _delete '\r' |