Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

cwenner
Copy link

@cwenner cwenner commented Jun 11, 2016

Hi!
The conda-auto-env script is really handy but I missed two features, here added:

  • Support for zsh.
  • Deactivating environments when leaving their directories.

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 just source (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 hooks zsh 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.)

cwenner added 5 commits June 11, 2016 18:27
[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.
@jeiros
Copy link

jeiros commented Aug 31, 2016

Hi! The script works well (it activates and deactivates the environments) but when using it with a GNU bash, version 4.3.42(1)-release (x86_64-apple-darwin15.0.0).

I get the following errors:

$ source conda_auto_env.sh
ps: cmd: keyword not found
ps: no valid keywords; valid keywords:

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 👍

emirlej pushed a commit to emirlej/conda-auto-env that referenced this pull request Aug 28, 2019
@emirlej
Copy link

emirlej commented Aug 28, 2019

Hi, any news if this is going to be merged 😄?

@cwenner
Copy link
Author

cwenner commented Aug 28, 2019

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.

fi
}

export PROMPT_COMMAND=conda_auto_env
# Check active shell.
if [[ $(ps -p$$ -ocmd=) == "zsh" ]]; then

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants