blob: 15276e701c513f98890b2a91ef0f3dc579b2eaf3 (
plain) (
blame)
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
|
#!/bin/bash
set -euo pipefail
# Usage: seed plant
if [ "$#" -ne 1 ] || [ "$1" != "plant" ]; then
echo "Usage: $0 plant"
exit 1
fi
if [ "$EUID" -eq 0 ]; then
echo "Do not run this script as root."
exit 1
fi
if ! command -v git >/dev/null 2>&1; then
echo "Warning: git is not installed. You won't be able to initialize a git repo."
fi
SRC_DIR="$(cd "$(dirname "$0")" && pwd)"
read -rp "Enter new project name: " DEST_DIR
if [ -z "$DEST_DIR" ]; then
echo "Project name cannot be empty."
exit 1
fi
DEST_PATH="$PWD/$DEST_DIR"
if [ -e "$DEST_PATH" ]; then
echo "Error: '$DEST_PATH' already exists."
exit 1
fi
cleanup() {
if [ -d "$DEST_PATH" ]; then
echo "Cleaning up partial directory..."
rm -rf "$DEST_PATH"
fi
}
trap cleanup INT TERM
echo "Copying seed template to '$DEST_PATH'..."
mkdir "$DEST_PATH"
if command -v rsync >/dev/null 2>&1; then
rsync -a --exclude='.git' --exclude='seed' "$SRC_DIR/" "$DEST_PATH/"
else
cp -r "$SRC_DIR/"* "$DEST_PATH/"
cp -r "$SRC_DIR/".* "$DEST_PATH/" 2>/dev/null || true
rm -rf "$DEST_PATH/.git" "$DEST_PATH/seed"
fi
cd "$DEST_PATH"
# Optionally, update README
if [ -f README.md ]; then
sed -i '' "1s/.*/# $DEST_DIR/" README.md 2>/dev/null || sed -i "1s/.*/# $DEST_DIR/" README.md
fi
echo "Initialized new project in '$DEST_PATH'."
read -rp "Do you want to initialize a git repository? (y/n): " INIT_GIT
if [[ "$INIT_GIT" =~ ^[Yy]$ ]]; then
git init
echo "Git repository initialized."
else
echo "Skipping git initialization."
fi
echo "Next steps:"
echo " cd \"$DEST_PATH\""
echo " and tend to the seed you've planted..."
|