Skip to content

Instantly share code, notes, and snippets.

@iandesj
Created June 12, 2024 04:00
Show Gist options
  • Save iandesj/86134f84b63cfea6833fa5daabec71e4 to your computer and use it in GitHub Desktop.
Save iandesj/86134f84b63cfea6833fa5daabec71e4 to your computer and use it in GitHub Desktop.
lazy way to spin up a new code project with bash fn
new() {
# Create a new project
# Usage: new project-name
# Options:
# --python: Initialize a new Python project
# --node: Initialize a new Node project
# --nuxt: Initialize a new Nuxt project
# --csharp: Initialize a new C# dotnet core MVC project
# --override: Override existing project
usage() {
echo "Usage: new project-name [--python|--node|--nuxt|--csharp] [--override]"
echo "Options:"
echo " --python: Initialize a new Python project"
echo " --node: Initialize a new Node project"
echo " --nuxt: Initialize a new Nuxt project"
echo " --csharp: Initialize a new C# dotnet core MVC project"
echo " --override: Override existing project"
}
if [ -z $1 ]; then
echo "Please provide a project name"
usage
return
fi
project_path=$HOME/Workspace/playground/$1
if [ -d $project_path ]; then
if [[ "$2" = "--override" || "$3" = "--override" ]]; then
echo "Are you sure you want to override the existing project? (y/N) "
read yn
case $yn in
[Yy]*)
;;
*)
echo "Aborted. Project not created"
return
;;
esac
echo "Overriding existing project"
cd $HOME/Workspace/playground
rm -rf $project_path
new $1 $2
else
echo "Project already exists :/ "
ls -l $project_path
fi
return
fi
mkdir -p $project_path
cd $project_path
git init
echo "# $1" >> README.md
git add .
git commit -m "task: Initial commit"
echo "Project created at $project_path"
case $2 in
--python)
echo "Initializing Python project"
poetry init -n
poetry add black flake8 pytest pytest-cov mypy pytest-asyncio --group dev
;;
--node)
echo "Initializing Node project"
yarn init
;;
--nuxt)
echo "Initializing Nuxt project"
npx nuxi@latest init $1
;;
--csharp)
echo "Initializing C# dotnet core MVC project"
dotnet new mvc
;;
*)
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment