-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitproj.sh
executable file
·41 lines (33 loc) · 931 Bytes
/
initproj.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
#!/usr/bin/env bash
set -eu
die() {
echo -e "\033[1;31mError: \033[m\033[1;38m$1\033[0m" >&2
exit 1
}
usage() {
echo "Usage: initproj.sh <project name>"
exit 1
}
## Make sure we have enough arguments.
test $# -eq 1 || usage
## Error if the project directory already exists and is not empty.
test -d "$1" && test -n "$(ls -A "$1")" && die "Directory $1 already exists and is not empty."
## Create the project directory.
mkdir -p "$1"
cd "$1"
mkdir out
## Copy files from the template directory.
dir="$(dirname "$(realpath "$0")")"
cp -r "$dir"/src src
cp -r "$dir"/idea .idea
cp "$dir"/.gitignore .
cp "$dir"/.clang-format .
cp "$dir"/CMakeLists.txt .
cp "$dir"/LICENCE .
## Replace the project name.
sed -i "s/hello/$1/g" CMakeLists.txt
sed -i "s/hello/$1/g" .gitignore
find .idea -type f -exec grep -q hello {} \; -print0 | xargs -0 sed -i "s/hello/$1/g"
## Initialise a git repository
git init
git add .