{
  pkgs,
  lib,
  ...
}: let
  blueprints = ./project-blueprints;
in {
  home.packages = [
    pkgs.tea
    (pkgs.writeScriptBin "create-project" ''
      #!${lib.getExe pkgs.nushell}

      def main [
        type?: string
        name?: string
        --local (-l)
      ] {
        if $name == null or $type == null {
          print "Usage: create-project <type> <name> [Options: -l]"
          exit 1
        }

        if ($name | str contains "/") or ($name | str contains ".") {
          print "This is not a valid name for a project"
          exit 1
        }

        if ($type | str contains "/") or ($type | str contains ".") {
          print "This is not a valid project type"
          exit 1
        }

        let blueprint_dir = $"${toString blueprints}/($type)"

        if ($blueprint_dir | path type) != "dir" {
          print "This project type doesn't exist"
          exit 1
        }

        mkdir $name
        cd $name

        if (ls $blueprint_dir | length) > 0 {
          glob $"($blueprint_dir)/*" | each { |file| cp --recursive $file . }
          ^chmod -R u+w .
        }

        if ("./init.sh" | path type) == "file" {
          bash "./init.sh" $name
          rm "init.sh"
        }

        echo "use flake" | save .envrc
        direnv allow

        git init
        git add .
        git commit -m "Project setup"

        if $local {
          print "You are all done"
          exit 0
        }

        ${lib.getExe pkgs.tea} repos create --name $name
        git remote add origin $"https://git.stribrny.org/max_ag/($name).git"
        git push -u origin main

        print "You are all done"
        exit 0
      }
    '')
  ];
}
