Support zsh and deactivate when leaving environment directories#4
Support zsh and deactivate when leaving environment directories#4cwenner wants to merge 10 commits intochdoig:masterfrom
Conversation
[fix] More accurate check of whether an environment is already active. Environments could previously be seen as active by certain spurious directory or environment names.
[feat] Environment deactivated in favor of the user's default conda environment when no longer in a subdirectory of the directory in which the active environment was activated.
[clean] Slightly reworded or added comments for clarity.
[clean] Slightly simplified expression: "-ne 0" for "-eq 0 .. else".
[feat] Support for sourcing in both bash and zsh without any extraneous commands. Kudos: birdsarah.
|
Hi! The script works well (it activates and deactivates the environments) but when using it with a I get the following errors: Would be nice to get it merged though, I was looking exactly for this automatic switching on and off of environments, so thanks for that 👍 |
|
Hi, any news if this is going to be merged 😄? |
|
Hi @emirlej. Thanks for the ping but I think this repo is presently stale. I would look through the 30 forks to find the one with features best matching your preferences. There is at least one other fork besides mine that adds the features of this PR. At the top of this PR, you can also find my branch. I haven't been using it for some time though so it may require updating. |
conda_auto_env.sh
Outdated
|
|
||
| export PROMPT_COMMAND=conda_auto_env | ||
| # Check active shell. | ||
| if [[ $(ps -p$$ -ocmd=) == "zsh" ]]; then |
There was a problem hiding this comment.
$(ps -p$$ -ocommand=) == "-zsh"
only this worked for me
OS Big Sur, zsh
fixed script to run on big sur
Hi!
The
conda-auto-envscript is really handy but I missed two features, here added:zsh.Also included some minor inconsequential changes to code and comments.
I hope these minor changes will be accepted.
zshell
Easybird gave an easy solution for modifying
.zshrcto support the script but it is better if the script works with justsource(and addresses some minor issues). At least, for me, I missed the comment and spent time on finding a workaround. The modification simply checks the active shell and hookszshdifferently.Deactivating environments
When working, often one will jump around between directories and this introduces the issue that whatever environment one was working with last sticks in the terminal. E.g., if one's default/root Conda environment has different versions or packages, these will be not be available after having entered a project directory. This behavior also persists to new tabs in a terminal. A simple work-around was to deactivate the current environment, in favor of the default, when no longer in a subdirectory of the directory that an environment was activated in.
(New pull request because I accidentally included an extraneous file.)