This post was supposed to be a monolith directory of all the CLI-based tooling that I use to get things done throughout my day, but it turned out to be just a bit too long so I elected to split it out into separate posts.
Okay so a few things:— Harsh Shandilya (@MSF_Jarvis) August 2, 2020
1. If my site was down for anybody yesterday, it was DNS, and I'm not even joking.
2. The post I promised about my terminal tooling became a bit too long, so instead I'm gonna be going over one tool a week to make it manageable for me and readable for you.
Let’s talk about direnv.
What is direnv?#
On the face of it, it’s not very interesting. Their GitHub description simply reads ‘Unclutter your .profile’, which gives you a general idea of what to expect but also grossly undersells it.
What direnv does, is improve the experience with things like 12 factor apps. It enables per-directory configurations that would otherwise be ‘global’. Let’s look into how I use it, to get a robust idea of what you can expect.
Why do I use it?#
I have a separate account for proprietary work related things here, which means that any GitHub tooling I use now needs to be configured with separate credentials for when I’m interacting with work repositories. Bummer!
direnv makes this simpler by allowing for environment variables to be set for those repositories only. I mostly use the official GitHub CLI from here to interact with the remote repo, so providing a separate GitHub token is just a matter of setting the
GITHUB_TOKEN environment variable to one that is allowed to interact with the current repo. With direnv, all you need to do is create a
.envrc file in the repository directory with this:
direnv will automatically set it when you enter the directory, and more importantly: reset it back to its previous value when you exit. This ‘unloading’ feature makes
direnv extremely powerful.
direnv also comes with a rich stdlib that lets you do far more than just export environment variables.
Setting up a Python virtualenv:
Stripping entries from
Adding entries into
You’ll notice an unfamiliar
rg -ccommand there, it’s ripgrep, and the
-cflag counts the number of matches in the string if there are any, and nothing otherwise. We’ll talk about it later in this series :)
The possibilities are huge! To check out the stdlib yourself, run
direnv stdlib after installing
This was part 1 of the Tools of the trade series.
You can sponsor me through GitHub to support this blog, my work on Password Store and all my other open source projects.