-
Notifications
You must be signed in to change notification settings - Fork 0
/
twig-snakecase-rename.sh
executable file
·68 lines (63 loc) · 1.67 KB
/
twig-snakecase-rename.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
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/sh
### git mv src/AppBundle/Resources/views/Thing/XxxXx -> templates/thing/xxx_xx
### git mv templates/Thing/XxxXx -> templates/thing/xxx_xx
if [ $# -eq 0 ]
then # set default locations
set -- src/AppBundle/Resources/views templates/
fi
snakeCase() {
sed '
# skip files overwriting bundles:
/templates\/bundles/ b
# move from old place:
s_src/AppBundle/Resources/views/_templates/_
# to snake case:
s/A\([^ ]*.twig\)/_a\1/g
s/B\([^ ]*.twig\)/_b\1/g
s/C\([^ ]*.twig\)/_c\1/g
s/D\([^ ]*.twig\)/_d\1/g
s/E\([^ ]*.twig\)/_e\1/g
s/F\([^ ]*.twig\)/_f\1/g
s/G\([^ ]*.twig\)/_g\1/g
s/H\([^ ]*.twig\)/_h\1/g
s/I\([^ ]*.twig\)/_i\1/g
s/J\([^ ]*.twig\)/_j\1/g
s/K\([^ ]*.twig\)/_k\1/g
s/L\([^ ]*.twig\)/_l\1/g
s/M\([^ ]*.twig\)/_m\1/g
s/N\([^ ]*.twig\)/_n\1/g
s/O\([^ ]*.twig\)/_o\1/g
s/P\([^ ]*.twig\)/_p\1/g
s/Q\([^ ]*.twig\)/_q\1/g
s/R\([^ ]*.twig\)/_r\1/g
s/S\([^ ]*.twig\)/_s\1/g
s/T\([^ ]*.twig\)/_t\1/g
s/U\([^ ]*.twig\)/_u\1/g
s/V\([^ ]*.twig\)/_v\1/g
s/W\([^ ]*.twig\)/_w\1/g
s/X\([^ ]*.twig\)/_x\1/g
s/Y\([^ ]*.twig\)/_y\1/g
s/Z\([^ ]*.twig\)/_z\1/g
# simple lowercase when not after a lowercase character
s/\([^a-z]\)_/\1/g
# simple lowercase when at start
s/^_//g
'
}
git ls-files "$@" | while read -r filename
do
tmp=$filename
new=$(echo "$tmp" | snakeCase)
while [ "$tmp" != "$new" ]
do
tmp=$new
new=$(echo "$tmp" | snakeCase)
done
if [ "$filename" = "$new" ]
then
# echo skip $filename, no change
continue
fi
mkdir -p "$(dirname "$new")"
git mv -v -- "$filename" "$new"
done