5 ms·
direnv is such a godsend that I shill for it on every team and in every company now, it's such a great tool.
by duped 5y ago
direnv is such a godsend that I shill for it on every team and in every company now, it's such a great tool.
- chrisweekly 5y agoI feel that way about z
- grappler 5y agodirenv should have been part of unix/linux/posix environments from the start. Whenever something's install steps tell you "go add this export statement to your .bashrc" or similar, it never sat well. That sort of thing should be scoped by path, and shell independent -- exactly the thing direnv enables.
- flurie 5y agoThe first thing I did recently in some cleanup work for a team was set up direnv and have it auto-switch kubernetes context by location.
- slig 5y agoI was reading the thread and thinking "this is a cool tool, might use someday". >have it auto-switch kubernetes context by location Now I'm sold, thanks!
- sundarurfriend 5y agoI never understood why people were so enamored with direnv, but this makes me understand it a bit. I don't think I need it right now, but I'll keep it in mind for this use case.
- ttyprintk 5y agoI alias ~~ to load .env if it exists, and unload the custom pieces if it doesn’t. I’ve seen people do that with :: as well.
- deleted 5y ago[deleted]
- hardwaresofton 5y ago100% agree. It's such a versatile tool -- for example I have the following: git config --local core.hooksPath $PWD/.githooks export DOCKER_CONFIG=$(realpath secrets/docker) Combine that with git-crypt[0] (obviously, don't commit secrets in plaintext to your repo!) for example and you have some really nice ergonomics. Not enough people know about direnv. [0]: https://www.agwa.name/projects/git-crypt/ https://www.agwa.name/projects/git-crypt/
- thenberlin 5y agoCould not agree more. I've shilled it three times in the past week alone. And I've also taken to mentioning it in any README involving env vars. Awesome tool.
- justin_oaks 5y agoI read through the direnv docs, but I'm trying to think of how I'd use it. Can you or anyone else give me some examples? Even just listing which directories you have .env or .envrc files in, and what environment variables you use in them.
- grappler 5y agoThe approach of using direnv and putting .env files in directories encouraged me to pull more variables from other places in config files, or shell scripts, or global variables in a programming project, and put them in environment variables instead. It's very aligned with the 12 factor philosophy [1]. Also, many scripts start by just defining a bunch of variables -- and many of those, in terms of other variables. Say, a PROJECT_ROOT directory, and a PROJECT_DOCS directory defined relative to that, etc. Then, a bunch of command parsing logic, after defining all those default values, so the user can set values of their own. Then, finally, the script can start doing the thing it was put there for in the first place. With the .envrc approach, some of that stuff is pulled out of the script (making it shorter and simpler) and considered part of the directory environment. [1] https://12factor.net/config
- 41b696ef1113 5y agoMy biggest use is for configuring database connections. Create something like `FOODATABASE=postgres://user:password@server:port/name` and then whenever I am inside the project, I source the FOODATABASE environment variable wherever it is needed. Another convenience pattern I use with Django is to have a PROJECT_IS_DEBUG key -iff variable is defined, enable extra tracing functionality without requiring any development specific configuration files. Example server pattern to default to production: if "PROJECT_IS_DEBUG" in os.environ: DEBUG = True ALLOWED_HOSTS = ["*"] else: # production configuration by default All for a one-time configuration setup. A further boon of this workflow is that systemd natively supports an EnvironmentFile configuration, so you can re-use the same configuration format from development to production.
- NateEag 5y agoProjects I work on wind up with a bin/ directory containing any number of little helper scripts and tools. With direnv that dir can automatically be first in your PATH when you're in the project, but not on it at all when you're elsewhere. Ditto for, say, putting a Python project's virtualenv/bin folder on PATH or a NodeJS project's node_modules/.bin. Projects I'm on also tend to wind up with an etc/ directory that configures things like PATH and tab completions for a good baseline experience - think of it as standardizing and isolating the snippets many projects tell you to put in your ~/.bashrc to work on the project. Direnv makes it easy to automatically load those, too. It really did revolutionize the way I work, by making it trivial to make projects much more self-contained, the way I'd always wanted them to be but hadn't been quite sure how to achieve. I've only used Nix for managing my personal installed package on OS X so far, but I believe direnv works really well in tandem with Nix - use a Nix file to define your project's dependencies and use direnv to automatically activate all those dependencies whenever you're in the project's directory.
- Spiritus 5y agoI've actually moved from direnv to shadowenv[1]. It's more powerful since it's using a Lisp dialect called Shadowlisp that lets you easily do things like append/prepend to $PATH, expand paths and other common actions. [1] https://shopify.github.io/shadowenv/ https://shopify.github.io/shadowenv/