forked from aternatik/dolibarr-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
newmodule.sh
executable file
·68 lines (60 loc) · 2.44 KB
/
newmodule.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
# Copyright (C) 2014 Raphaël Doursenaud
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
VERSION=0.0.1
USAGE="Usage: newmodule.sh NewName"
# TODO: check depedencies presence (find, sed and rename)
# TODO: allow execution from build directory
# TODO: validate parameter
# TODO: use multiple word parameter, for example "My module is awesome" which should lead to "MyModuleIsAwesome" and "mymoduleisawesome" so we can also fix language strings
# TODO: add module ID management (language files…)
# TODO: add oneliner description management
# TODO: add copyright management
if [ $# == 0 ] ; then
echo ${USAGE}
exit 1;
fi
ToLower () {
echo $(echo $1 | tr '[:upper:]' '[:lower:]')
}
ToUpper () {
echo $(echo $1 | tr '[:lower:]' '[:upper:]')
}
CAMELORIG="MyModule"
LOWERORIG=$(ToLower ${CAMELORIG})
UPPERORIG=$(ToUpper ${CAMELORIG})
cameltarget=$(echo $1)
lowertarget=$(ToLower $1)
uppertarget=$(ToUpper $1)
thisscript=`basename $0`
# Rewrite occurences
find . -not -iwholename '*.git*' -not -name "${thisscript}" -type f -print0 | xargs -0 sed -i'' -e"s/${CAMELORIG}/${cameltarget}/g"
find . -not -iwholename '*.git*' -not -name "${thisscript}" -type f -print0 | xargs -0 sed -i'' -e"s/${LOWERORIG}/${lowertarget}/g"
find . -not -iwholename '*.git*' -not -name "${thisscript}" -type f -print0 | xargs -0 sed -i'' -e"s/${UPPERORIG}/${uppertarget}/g"
# Rename files
for file in $(find . -not -iwholename '*.git*' -name "*${CAMELORIG}*" -type f)
do
rename ${CAMELORIG} ${cameltarget} ${file}
done
for file in $(find . -not -iwholename '*.git*' -name "*${LOWERORIG}*" -type f)
do
rename ${LOWERORIG} ${lowertarget} ${file}
done
for file in $(find . -not -iwholename '*.git*' -name "*${UPPERORIG}*" -type f)
do
rename ${UPPERORIG} ${uppertarget} ${file}
done
# TODO: add instructions about renaming vars (ack --php -i my)
# TODO: add instructions about renaming files (ls -R|grep -i my)