hyperupcall / autoenv

Directory-based environments.
MIT License
5.72k stars 261 forks source link

autoenv_init: Only activate envs between PWD and previous dir #237

Closed tomtseng closed 4 months ago

tomtseng commented 5 months ago

Fixes #228.

Issue

Suppose we cd from /a/b/c to /a/y/z.

Expected behavior: Presumably we've already invoked /.env, /a/.env, and /a/b/.env when we cded into /a/b/c, so I expect now cding into a/y/z/ to only invoke /a/y/.env and /a/y/z/.env.

Actual behavior: Invokes envs in all ancestors of /a/y/z: /.env, /a/.env, /a/y/.env, and /a/y/z/.env.

Changes

hyperupcall commented 4 months ago

Thanks for the PR! Although this is a clean fix, I worry that addressing this issue will cause breakage. The readme states:

When executing, autoenv, will walk up the directories until the mount point and execute all .env files beginning at the top.

I don't want to make any changes that run contrary to that, since it's the intended behavior, even if it's possibly counter-intuitive.

I thought of one tangible case that could break downstream consumers: