From c20d19b024dc3aa351f875e5f080108858ab44ae Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sun, 3 Mar 2024 20:34:09 -0600 Subject: [PATCH] Add Tell direnv To Load The Env File as a Unix TIL --- README.md | 3 ++- unix/tell-direnv-to-load-the-env-file.md | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 unix/tell-direnv-to-load-the-env-file.md diff --git a/README.md b/README.md index 37fbc31..68a4772 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1387 TILs and counting..._ +_1388 TILs and counting..._ --- @@ -1406,6 +1406,7 @@ _1387 TILs and counting..._ - [Specify The Language For A File With Bat](unix/specify-the-language-for-a-file-with-bat.md) - [Sort In Numerical Order](unix/sort-in-numerical-order.md) - [Switch Versions of a Brew Formula](unix/switch-versions-of-a-brew-formula.md) +- [Tell direnv To Load The Env File](unix/tell-direnv-to-load-the-env-file.md) - [Touch Access And Modify Times Individually](unix/touch-access-and-modify-times-individually.md) - [Undo Some Command Line Editing](unix/undo-some-command-line-editing.md) - [Update Package Versions Known By asdf Plugin](unix/update-package-versions-known-by-asdf-plugin.md) diff --git a/unix/tell-direnv-to-load-the-env-file.md b/unix/tell-direnv-to-load-the-env-file.md new file mode 100644 index 0000000..a9714d5 --- /dev/null +++ b/unix/tell-direnv-to-load-the-env-file.md @@ -0,0 +1,22 @@ +# Tell direnv To Load The Env File + +By default [`direnv`](https://direnv.net/) looks for and evaluates the `.envrc` +file that appears in a given project directory. This default behavior is good +for things like setting certain path dependencies (e.g. a specific version of +node or postgres). + +To the end of using `direnv` to set up the development environment, it can be +useful to have it also load the `.env` file into the current shell's +environment. + +To get `direnv` to do that, add this line to the `.envrc` file: + +``` +dotenv_if_exists .env +``` + +This specific loads all the environment variables in `.env`. If there are other +files, such as `.env.development` that need to be loaded in, those can be +included with additional +[`dotenv_if_exists`](https://direnv.net/man/direnv-stdlib.1.html#codedotenvifexists-ltdotenvpathgtcode) +declarations.