Support for an expanded set of variable expansion
Is your feature request related to a problem? Please describe. I am working on a project which includes docker compose.
While I understand docker-compose has its own ability to load an .env file, I like the ability to share the set of environment variables between my docker containers and my host machine.
Thus, in my .envrc, I dotenv the same .env file I use for my docker compose file.
Sadly, it appears direnv supports a very minimal set of variable expansions. Even fewer than the restricted set docker compose supports.
Thus, my ability to use these variable expansions is limited.
In fact, since compose loads preferentially from the shell environment over the .env file, if I do load these environment variables, they will be broken on the launched container.
Describe the solution you'd like An expanded set of variable expansions being added.
I figured a minimal-enough set would be docker-compose's set, which is, as of my knowledge as of writing:
| $VAR / ${VAR} | Basic substitution |
| ${VAR:-default} | Default if unset or empty |
| ${VAR-default} | Default if unset only |
| ${VAR:?error} | Error if unset or empty |
| ${VAR?error} | Error if unset only |
| ${VAR:+value} | Use value if set and not empty |
| ${VAR+value} | Use value if set (even if empty) |
Describe alternatives you've considered
- Manually expanding the variables with an extra script.
- This feels bulky and unnecessary for such a basic feature, IMO.
- Also means I also have to have a second environment-processing program in my development environment to get anything done.
- Keeping two separate .env files
- It feels more cumbersome than necessary, if I'm mostly using docker compose for a development environment anyways
Source: direnv/direnv