I now have a pretty structured way to configure my projects -- I use Nix and direnv and then the language-specific files. But when I setup a new project, it's been a bit of a mess. What I used to do is something like:
- Find a project that is similar to the new one I'm making...Python, Node, Java, etch
- copy that old project's
.envrc
andshell.nix
file to the new project. And probably thedocker-compose.yml
and maybe assorted other files - tweak as necessary
- Find other file and tweak as necessary
I really got tired of doing this. Sometimes there was nothing to tweak but I looked anyway and sometimes I didn't have quite what I wanted. I said to myself "Surely someone else has solved this problem!". I used Lazybones many years ago...and it hasn't been updated in a long time (maybe since I used it last!) so I decided to keep looking and somehow I stumbled onto CookieCutter, which pretty much solves all my problems.
There are a lot of CookieCutter templates out there but I wanted something of my own. Luckily it's easy to make your own templates. You can check out my Github Repo. I found them pretty easy to make though there are some things I don't like about it -- like using a Jinja template to generate a folder name, which means you have folders named {{cookiecutter.project_name}}
. For me that is weird to see on the command line but it's a small nit and one I've chosen to live with.. Anyway, not only did I put in Nix and Direnv configs but also docker-compose.yml
with Postgresql (my db of choice) and default script names, with the db name and the project name configurable.. I also do a git init
at the end, because I will put it in git eventually (though not necessarily push it anywhere).
Basically, you store your templates, er, cookie cutters, in $HOME/.cookiecutters
and set each project type as a folder.. Or fork mine and check it out into that folder. I installed cookiecutter through my package manager and that makes the exe really long (cookiecutter-3.10
), so I made two aliases:
alias new_proj="cookiecutter-3.10"
alias list_proj="cookiecutter-3.10 -l"
So if I want to know the names of my template types, I type list_proj
. When I want a new project, I use new_project [type]
, and then follow the prompts. It now takes me 3 seconds to start a new project source instead of a few minutes and, even better, less cognitive load. Just find what template that I have that works best and new_proj type
and I'm ready to get started.