-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support zsh and deactivate when leaving environment directories #4
base: master
Are you sure you want to change the base?
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
fi | ||
} | ||
|
||
export PROMPT_COMMAND=conda_auto_env | ||
# Check active shell. | ||
if [[ $(ps -p$$ -ocmd=) == "zsh" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$(ps -p$$ -ocommand=) == "-zsh"
only this worked for me
OS Big Sur, zsh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed script to run on big sur
Hi!
The
conda-auto-env
script 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
.zshrc
to 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 hookszsh
differently.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.)