From 7f04eabbbfa67488df9a788b5b17072eddf52a73 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Tue, 4 Aug 2020 14:23:00 +0530 Subject: [PATCH] Add first part of the 'Tools of the trade' series Signed-off-by: Harsh Shandilya --- content/posts/tools-of-the-trade-direnv.md | 56 ++++++++++++++++++ static/uploads/tools-of-the-trade-direnv.webp | Bin 0 -> 4838 bytes 2 files changed, 56 insertions(+) create mode 100644 content/posts/tools-of-the-trade-direnv.md create mode 100644 static/uploads/tools-of-the-trade-direnv.webp diff --git a/content/posts/tools-of-the-trade-direnv.md b/content/posts/tools-of-the-trade-direnv.md new file mode 100644 index 0000000..00c4e8b --- /dev/null +++ b/content/posts/tools-of-the-trade-direnv.md @@ -0,0 +1,56 @@ ++++ +categories = ["tools-of-the-trade"] +date = 2020-08-04 +description = "In the first post in the new 'Tools of the trade' series, we talk about direnv." +draft = true +slug = "tools-of-the-trade-direnv" +socialImage = "uploads/tools-of-the-trade-direnv.webp" +tags = ["direnv", "cli-tools"] +title = "Tools of the trade: direnv" ++++ + +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. + +{{< tweet 1289965196992114689 >}} + +Let's talk about [direnv](https://github.com/direnv/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](https://en.wikipedia.org/wiki/Twelve-Factor_App_methodology). 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](https://github.com/hshandilya-navana), 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](https://github.com/cli/cli) 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, its just a matter of creating a `.envrc` file in the repository directory with this: + +```bash +export GITHUB_TOKEN= +``` + +and `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. + +{{< asciinema qMkuyVjPSkhNqO6Jo0eQnLiyt >}} + +`direnv` also comes with a rich stdlib that lets you do far more than just export environment variables. + +Setting up a Python virtualenv: + +{{< asciinema irkZWRh00gFVIcH41BRcOvowm >}} + +Stripping entries from `$PATH`: + +{{< asciinema vbzolwrYnXzBFvhAqMJEFBNRv >}} + +Adding entries into `$PATH`: + +{{< asciinema C1EhhAoy1y3vSwJaIc0R8o0RY >}} + +> You'll notice an unfamiliar `rg -c` command there, it's [ripgrep](https://github.com/BurntSushi/ripgrep), and the `-c` flag 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 `direnv`. + +This was part 1 of the [Tools of the trade](/categories/tools-of-the-trade/) series. diff --git a/static/uploads/tools-of-the-trade-direnv.webp b/static/uploads/tools-of-the-trade-direnv.webp new file mode 100644 index 0000000000000000000000000000000000000000..fe847f6bc124fddb01c1bf1f93926afb96475419 GIT binary patch literal 4838 zcmb7|S5y;<(uGqAARYyD~!wr{uit$=7$IhG^}X`LC)`8NyRzqH0$C0ksA#f5}~nqHiJUtZi+1#q_m0 zVJqs}=C|!ahkQI3hJH5-{?P;?@kb{qf`UsIC-c~gv%~+nTwI(Fv9gdG)`m-e%m+Y0 zyuPuScrq9@^d+d6XJ@zFX$hCo=^&Fgg}wGO9MD7FYitOa^3h;)P6+Y0(!X%Jp}&j% zh;2{E0oBd9qm)$gjnb*d!q5~fQ!6a1Qsiz*QWq3Qdx526ZG+4Nd|AS?h$Rp3UNy~9 zsy)Xt21g=o_MNVKs=Av%U-(ZB9(vmbq8pl8S>=3V=?R$^h(&vJ{;9|*KvuUSNP1Vm zOw;18!@jk%U+1B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