This repository has been archived by the owner on Oct 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepare.sh
executable file
·81 lines (59 loc) · 1.47 KB
/
prepare.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
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
chmod_files()
{
for file in "$1"/*; do
[[ ! -d $file ]] && chmod +x "$file"
done
}
make_new_path()
{
local path="$1"
local dir="$(dirname "$path")"
local base="$(basename "$path" | sed "s/^sub/${SUBNAME}/g")"
echo "$dir/$base"
}
prepare_sub() {
local path="$1"
local newpath="$(make_new_path "$path")"
if [[ -d $path ]]; then
for file in "$path"/sub-*; do
prepare_sub "$file"
done
chmod_files "$path"
elif [[ -f $path ]]; then
sed -i "s/\b\(_\)\?sub\b/\1$SUBNAME/g;s/\b_SUB_ROOT\b/_$ENVNAME/g" "$path"
fi
mv "$path" "$newpath"
}
NAME="$1"
if [[ -z $NAME ]]; then
echo "usage: prepare.sh NAME_OF_YOUR_SUB" >&2
exit 1
fi
SUBNAME=$(echo $NAME | tr '[A-Z]' '[a-z]')
ENVNAME="$(echo $NAME | tr '[a-z-]' '[A-Z_]')_ROOT"
echo "Preparing your '$SUBNAME' sub!"
if [[ $NAME != "sub" ]]; then
rm bin/sub
for file in **/sub*; do
prepare_sub "$file"
done
chmod_files "libexec"
ln -s ../libexec/$SUBNAME bin/$SUBNAME
fi
rm README.md
rm prepare.sh
cat << DONEMSG
Done! Enjoy your new sub! If you're happy with your sub, run:
rm -rf .git
git init
git add .
git commit -m 'Starting off $SUBNAME'
./bin/$SUBNAME init
You can remove the example when you no longer need it:
rm -r libexec/${SUBNAME}-example
Made a mistake? Want to make a different sub? Run:
git add .
git checkout -f
Thanks for making a sub!
DONEMSG