BASH
Create and Navigate to New Project Directory
Automate the creation of a new project directory structure and immediately navigate into it, streamlining development setup for web projects.
#!/bin/bash
create_project_dir() {
if [ -z "$1" ]; then
echo "Usage: create_project_dir <project_name>"
return 1
fi
PROJECT_NAME=$1
mkdir -p "$PROJECT_NAME" && cd "$PROJECT_NAME"
echo "Created and navigated to $PROJECT_NAME/"
# Example: create some basic files common in web projects
touch index.html package.json README.md
echo "Initialized basic project files."
}
# To use:
# create_project_dir my-web-app
How it works: This Bash script defines a function `create_project_dir` that simplifies the setup of new web projects. It takes a project name as an argument, creates a new directory with that name, immediately changes into it, and then initializes common project files like `index.html`, `package.json`, and `README.md`. This automation speeds up the initial scaffolding phase of development.