-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-repo
executable file
·106 lines (86 loc) · 1.93 KB
/
init-repo
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
# Default directory
DEFAULT_DIR="$HOME"
# Function to display usage information
usage() {
echo "Usage: $(basename "$0") [-h|-l|-p|-w] <project_name>"
echo "Options:"
echo " -h User Home Directory (Default)"
echo " -l Learning projects"
echo " -p Personal projects"
echo " -w Work projects"
exit 1
}
# Function to create a basic .gitignore file
create_gitignore() {
cat << EOF > .gitignore
# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Editor directories and files
.idea/
.vscode/
*.swp
*.swo
*~
# Logs and databases
*.log
*.sql
*.sqlite
# Build output directories
/build/
/dist/
/out/
# Dependency directories
/node_modules/
/jspm_packages/
/bower_components/
# Environment files
.env
.env.local
.env.*.local
# Other common files to ignore
*.tmp
*.bak
*.cache
EOF
}
# Parse command-line options
while getopts ":hlpw" opt; do
case $opt in
h) DIR="$DEFAULT_DIR" ;;
l) DIR="$DEFAULT_DIR/Developer/Learning" ;;
p) DIR="$DEFAULT_DIR/Developer/Projects" ;;
w) DIR="$DEFAULT_DIR/Developer/Work" ;;
\?) echo "Invalid option -$OPTARG" >&2; usage ;;
esac
done
# Shift the parsed options out of the arguments list
shift $((OPTIND-1))
# Check if project name is provided
if [ -z "$1" ]; then
echo "Error: No project name provided."
usage
fi
# Define project name and directory
PROJECT_NAME="$1"
PROJECT_DIR="${DIR:-$DEFAULT_DIR}/$PROJECT_NAME"
# Create the directory if it doesn't exist
mkdir -p "$PROJECT_DIR"
# Navigate to project directory
cd "$PROJECT_DIR" || exit 1
# Initialize a Git repo
git init
# Create a README file
echo "# $PROJECT_NAME" > README.md
# Create a comprehensive gitignore file
create_gitignore
# Add and commit the README file
git add README.md .gitignore
git commit -m "Initial commit: Project setup"
echo "Repository $PROJECT_NAME initialized in $PROJECT_DIR"