virtualfish
virtualfish copied to clipboard
Starting fish sub-shells with activated environment
This is a draft PR regarding #254
Added the following changes:
- export _VF_EXTRA_PATH which we can use to know if virtualfish was the one to set this or not (just VIRTUAL_ENV would be ambiguous)
- on active: prepend _VF_EXTRA_PATH to fish_user_paths (which will automatically update PATH) (note: use -g here to NOT set it as universal variables, because -x does not actually do anything in this case)
- on deactivate: clear BOTH
fish_user_pathsandPATH(_VF_EXTRA_PATH may be part of only PATH if we are in a sub-shell because fish_user_paths is restored at fish startup) and delete _VF_EXTRA_PATH - on
virtual.fishload: if we are in a virtual environment, set by virtualfish AND _VF_EXTRA_PATH does not appear in fish_user_paths, then we just loaded into a sub-shell and must re-order _VF_EXTRA_PATH to the front of fish_user_paths (and out of regular PATH) - added a lot of debug output to make testing and reasoning easier
- I tried changing as little as possible otherwise
Use cases I have tried:
- activating and deactivating an environment
- spawning sub-shells with activated and deactivated environment
- reloading virtual.fish by sourcing it again (is guarded against by the not contains -- "$_VF_EXTRA_PATH" $fish_user_paths)
I added a lot of debug output to make it easy to test, for actually merging this would of course be removed!
I just realized, we could also not use fish_user_paths at all, keeping the normal PATH, but still move the _VF_EXTRA_PATH to the front (because fish_add_paths did not end up working as expected anyway). Just as a possible option I wanted to add