direnv with WSL2 - not loading files when used with source_env_if_exists

894 Views Asked by At

(this is to document a specific behavior that may affect users mixing windows and wsl for work)

I use a hierarchy of directories with .envrc in them to manage environment.

file content is like

export BASE_URL="url"
source_env_if_exists .terraform-state

First line works, second appears to be not doing anything. source_env_if_exists is direnv library call (https://github.com/direnv/direnv/blob/master/stdlib.sh)

Local environment is WSL2(Ubuntu), where the file is part of directory checked out on windows but used with in WSL

1

There are 1 best solutions below

0
Jayan On

File is edited/cloned from windows leaves line ending in windows style. direnv library leaves that to bash (and does nothing) . Windows WSL - issue with carriege return · Issue #542 · direnv/direnv · GitHub has more details.

Fixing the file (using dos2linux or fresh clone from WSL2 ) worked.