Unmangling paths set by direnv on Windows 11
Thu 4 Jan 2024 11:25 CET
direnv
works fine on Windows 11, but if an .envrc
tries to set the PATH
, the result will
be a path in Windows format, not Unix format.1
Instead of adding eval $(direnv hook bash)
to your .bashrc
, try the following snippet:
This modifies the output of direnv hook bash
slightly, adding code to fix path-like variables
after direnv
sets the environment up.2
The variable names to unmangle are drawn from a new variable, _unmangle_direnv_names
,
initially set to PATH
, which should contain a space-separated list of variable names.
If, in a particular .envrc
, you need path-unmangling for an additional variable, you can add
that variable’s name to _unmangle_direnv_names
. For example,
will unmangle both PATH
and XPATH
.
-
While experimenting, I discovered
direnv export json
! Very nice. It’s great to see more and more tools using structured data for their inputs and outputs. ↩