-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabify
executable file
·68 lines (56 loc) · 1.29 KB
/
tabify
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
62
63
64
65
66
67
68
#!/bin/bash
usage() {
script="./$(basename "$0")"
cat <<-DOC
Usage: $script {-s|-t} PATTERN
Converts files from spaces to tabs, or vice versa.
Example: To convert a bunch of files to spaces that are named like "file123.py"
$script -s "fi*.py"
Both Sublime Text and VS Code space/tab convertor behave identically. They only touch leading characters,
and not inline text (say vertically aligned comments). This tool differs by converting the entire file.
Options:
-s, --spaces convert file(s) to spaces
-t, --tabs convert file(s) to tabs
-h, --help show this help message
DOC
}
spaces=false
tabs=false
if [ $# -eq 0 ]; then
echo "Try '$script --help' for more information."
exit 1
fi
while [ $# -gt 0 ]; do
case $1 in
-s | --spaces)
spaces=true
;;
-t | --tabs)
tabs=true
;;
-h | --help)
usage
exit 1
;;
*)
glob=$1
;;
esac
shift
done
if [ -z "$glob" ]; then
echo "error: must specify a glob pattern"
exit 1
fi
if $spaces; then
exp="expand -t 4"
elif $tabs; then
exp="unexpand -t 4"
else
usage
exit 1
fi
find ! \( -path "*/.git" -prune \
-o -path "*/venv" -prune \
-o -path "*/.idea" -prune \) -type f -name "$glob" \
-exec bash -c 'cp "$0" /tmp/e; $1 /tmp/e > "$0"; echo Reformatted: "$0"' {} "$exp" \;