Direnv: [feature-request] Load environment from .envrc in parent folders

Created on 27 Nov 2015  ยท  3Comments  ยท  Source: direnv/direnv

Hey, all.

I have following use case: I've got $GOPATH set in .envrc to $PWD, in src I have a project with another .envrc file to set $GO15VENDOREXPERIMENT environment variable. When I go to the folder of my project in src dir, $GOPATH is removed from the environment.

Here is a file system tree for this case

 โ†’ tree
.
โ”œโ”€โ”€ .envrc                    # .envrc to set $GOPATH
โ””โ”€โ”€ src                       #
    โ””โ”€โ”€ github.com            #
        โ””โ”€โ”€ Altoros           #
            โ””โ”€โ”€ my-project    #
                โ”œโ”€โ”€ .envrc    # .envrc to set $
                โ””โ”€โ”€ vendor
                    โ””โ”€โ”€ github.com
                        โ””โ”€โ”€ ...

As I understand from this doc, direnv stops searching for another .envrc files after it finds one. Still possibly for this case it would be better to search all parents.

What do you think?

Most helpful comment

Hi @allomov,

did you have a look at the stdlib as well ? By adding source_up in your child's envrc it will load the parent's envrc.

All 3 comments

Hi @allomov,

did you have a look at the stdlib as well ? By adding source_up in your child's envrc it will load the parent's envrc.

This is very nice, thank you!

If anyone found this issue via github, the full stdlib docs are now found here

Was this page helpful?
0 / 5 - 0 ratings