autoenv icon indicating copy to clipboard operation
autoenv copied to clipboard

Can I deactivate used env if I cd to folder

Open enagorny opened this issue 13 years ago • 8 comments

Could current activated env be deactivated if I cd to folder which is not subfolder of current directory?

Also if I using such .env: source oenv/bin/activate it works when I enter to this folder, but then when I go to subfolder I'm getting: bash: oenv/bin/activate: No such file or directory I can fix it using absolute path, but it will be activated twice, isn't it.

enagorny avatar Mar 21 '12 13:03 enagorny

This would be nice, but since the scope of .env right now is "any bash script", it's not really an easy thing to do.

We could reset environment variables to their original state.

kennethreitz avatar Mar 31 '12 05:03 kennethreitz

Agreed that this would be a good feature. What if you cd to a directory containing a .env, and then cd to another directory containing another .env? Maybe you want the cumulative effects of the two envs, but probably not.

I have similar sort of project that handles deactivating envs: https://bitbucket.org/krupan/albion/wiki/Home

Feel free to copy any of it, or to tell me it's stupid :-)

krupan avatar Jul 13 '12 16:07 krupan

:+1:

jeantil avatar Jan 31 '13 09:01 jeantil

+1

hwangmoretime avatar Mar 23 '15 03:03 hwangmoretime

:+1: for resetting environment variables.

@kennethreitz Limiting the scope for environment variables only (not any bash script) sounds good, but dramatically changes the functionality of autoenv, right?

zambon avatar Mar 15 '16 19:03 zambon

Correct.

kennethreitz avatar Mar 15 '16 21:03 kennethreitz

How about calling a tear down function (on_leave?) if it is defined in .env? For example, to deactivate a condo environment one might define this function in .env.

function on_leave() {
    echo "Deactivating environment"
    source deactivate
}

I haven't considered the details but would something like this be useful?

robcowie avatar Mar 26 '16 13:03 robcowie

i mkdir "dac" a directory and touch .env with the line in the "dac"

deactivate cd ..

now i can cd dac and deactivate and back

HSin-Tse avatar Jun 24 '17 12:06 HSin-Tse

Closing as this has been implemented in v0.3.0 with the .env.leave file. It's not perfect and you would have to manually "deactive" the environment you have setup (i am keeping autoenv as simple as possible), but it is what you would if you want to do this. Sorry for the pings - I know this is an old thread.

hyperupcall avatar Oct 14 '23 03:10 hyperupcall