Direnv - and reinventing the wheel with envloader
I hate having to do this. But I have.
I’ve made ANOTHER tool to load up your env vars in a terminal. Why? Because I had a mare getting direnv to work on my specific Windows machine. It was really due to the way our office locked down the way a users $PROFILE
works - that is it puts everything on OneDrive and there was a ton of admin issues getting it all working correctly. So, stupidly, rather than fixing that properly I found it (more fun?) to build a cross platform simplifed direnv tool.
So its called envloader, FInd details here and how to use.
In short Let’s imagine your directory - or one above it - has a .env or a .envrc file. It might look like this.
MICROSOFT_TOKEN_TRANS="token-for-trans"
CONFIG_ENCRYPTION_KEY="RqliKRLnkQxTOzgx_molctcWXM_alqSaNYVxCTBjma0="
SIMPLE_VAR=hello123
JSON_VAR='{"name": "test", "value": 42}'
This is common syntax for dotenv and direnv, but it won’t work as-is across all terminals. You need a tool to convert it properly for your shell. direnv IS your tool of choice, but if you like me, you cant just get it working - or the numerous other tools out there like it and you spend too many hours fiddling to get them to work (because you have a Windows machine which has really tight admin rights on it) you could try this little tool I’ve made..
Install on Mac/Linux
brew tap willwade/envloade
brew install willwade/envloader/envloader
or Using Scoop
scoop bucket add envloader https://github.com/willwade/envloader
scoop install envloader
then in a terminal you can run envloader
and press enter. It will find a .env or .envrc and convert the lines appropriately for your shell.
e.g.
envloader
Make your life a bit easier and write an alias in your env - details here
I haven’t gone to town building lots of neat integration tricks - and unlike direnv it DOESN’T autoload on entering/exiting a directory. But running ‘envload’ now does the trick just fine for me. Maybe for you too.