-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewproject
executable file
·51 lines (38 loc) · 1.12 KB
/
newproject
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
#!/bin/bash
FILES_TO_COPY="Makefile .gitignore"
print_usage() {
>&2 echo "Usage:"
>&2 echo "$0 DIRECTORY BINARY_NAME"
exit 1
}
[[ ! "$#" -eq 2 ]] && print_usage
TARGET_DIR="$1"
BINARY_NAME="$2"
TARGET_DIR="$(realpath "$TARGET_DIR")"
echo "Initializing project into $TARGET_DIR"
# Ask for confirmation if any files will be overwritten
FILES_TO_OVERWRITE=""
for filename in $FILES_TO_COPY; do
if [[ -e "$TARGET_DIR/$filename" ]]; then
FILES_TO_OVERWRITE="$FILES_TO_OVERWRITE$filename "
fi
done
if [[ -n "$FILES_TO_OVERWRITE" ]]; then
echo "The following files in $TARGET_DIR will be overwritten:"
echo `tput setaf 1`"$FILES_TO_OVERWRITE"`tput sgr0`
read -p "Continue (y/n)? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# Go to this script's directory, where the files reside
cd $(dirname "$BASH_SOURCE")
mkdir -p "$TARGET_DIR"
cp -f Makefile "$TARGET_DIR/Makefile"
cp -f gitignore "$TARGET_DIR/.gitignore"
sed -i -e "s/BINARYNAME_PLACEHOLDER/$BINARY_NAME/" \
"$TARGET_DIR/Makefile" "$TARGET_DIR/.gitignore"
mkdir -p "$TARGET_DIR/src"
mkdir -p "$TARGET_DIR/include"
echo "Initialization completed!"