-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrename_cpp.sh
executable file
·37 lines (28 loc) · 1 KB
/
rename_cpp.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
#!/usr/bin/env bash
# This scripts renames the name of a class as well as its header and cpp file
# (assuming they are the lowercase version of the class name).
#
# Usage: ./scripts/rename_cpp.sh src/core QgsMyClassName QgsMyNewClassName
set -e
# GNU prefix command for bsd/mac os support (gsed, gsplit)
GP=
if [[ "$OSTYPE" == *bsd* ]] || [[ "$OSTYPE" =~ darwin* ]]; then
GP=g
fi
FILEPATH=$1
OLD_CLASSNAME=$2
NEW_CLASSNAME=$3
OLD_CLASSUPPER="${OLD_CLASSNAME^^}"
OLD_CLASSLOWER="${OLD_CLASSNAME,,}"
NEW_CLASSUPPER="${NEW_CLASSNAME^^}"
NEW_CLASSLOWER="${NEW_CLASSNAME,,}"
FILES=$(git grep $OLD_CLASSLOWER -- src python | cut -d: -f1)
for f in ${FILES}; do
echo "replacing in $f..."
${GP}sed -i "s/\b${OLD_CLASSNAME}\b/${NEW_CLASSNAME}/g" $f
${GP}sed -i "s/\b${OLD_CLASSUPPER}\b/${NEW_CLASSUPPER}/g" $f
${GP}sed -i "s/\b${OLD_CLASSLOWER}\b/${NEW_CLASSLOWER}/g" $f
done
set +e
mv ${FILEPATH}/${OLD_CLASSLOWER}.h ${FILEPATH}/${NEW_CLASSLOWER}.h
mv ${FILEPATH}/${OLD_CLASSLOWER}.cpp ${FILEPATH}/${NEW_CLASSLOWER}.cpp