-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_project.sh
More file actions
executable file
·50 lines (39 loc) · 1.13 KB
/
init_project.sh
File metadata and controls
executable file
·50 lines (39 loc) · 1.13 KB
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
#!/usr/bin/env bash
if [ ! -d src ]; then
echo "error: must run from root directory or already initialized" >&2
exit 2
fi
if [ $# -ne 1 ]; then
echo "usage: $0 new_name" >&2
exit 1
fi
new_name=$1
if ! echo "$new_name" | grep -Eq '^[a-z]*$'; then
echo "error: new name must match '^[a-z]*$'" >&2
exit 3
fi
upper=$(echo $new_name | tr [:lower:] [:upper:])
lower=$(echo $new_name | tr [:upper:] [:lower:])
if [ -d '.git' ]; then
git="git "
fi
for f in $(grep -irl example --exclude-dir='build' --exclude-dir='.*' \
| grep -v $(basename $0)); do
bname=$(basename "$f")
if echo "$bname" | grep -Eq '^\.'; then
continue
fi
echo "Updating $bname"
sed -i "s/example/$lower/g" "$f"
sed -i "s/EXAMPLE/$upper/g" "$f"
done
for f in $(find . -type f -iname '*example*' -not -path './build*'); do
${git}mv $f $(echo $f | sed "s:/\([^/]*\)example\([^/]*\)$:/\1${lower}\2:")
done
for f in $(find . -type d -iname '*example*' -not -path './build*'); do
${git}mv $f $(echo $f | sed "s:example:${lower}:")
done
mv -v example $new_name
echo
echo "1. Remove this script with \`${git}rm $0\`"
echo "2. Update README.md"