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

Allow to show conda environment basename #594

Open
2 tasks
memeplex opened this issue May 14, 2021 · 6 comments
Open
2 tasks

Allow to show conda environment basename #594

memeplex opened this issue May 14, 2021 · 6 comments

Comments

@memeplex
Copy link

General information

System report (output of prompt_pure_system_report):

  • Zsh: zsh 5.8 (x86_64-apple-darwin20.1.0) (/usr/local/bin/zsh)
  • Operating system: macOS 11.3.1 (20E241)
  • Terminal program: iTerm.app (3.4.6)
  • Tmux: no
  • Git: git version 2.30.1 (Apple Git-130)
  • Pure state:
    • username: ''
    • prompt:
    • version: 1.13.0
  • zsh-async version: 1.8.4
  • PROMPT: typeset -g PROMPT=$'%F{${prompt_pure_colors[path]}}%~%f %}%(12V.%F{$prompt_pure_colors[virtualenv]}%12v%f .)%(?.%F{$prompt_pure_colors[prompt:success]}.%F{$prompt_pure_colors[prompt:error]})${prompt_pure_state[prompt]}%f '
  • Colors: typeset -g -A prompt_pure_colors=( [execution_time]=yellow [git:action]=yellow [git:arrow]=cyan [git:branch]=242 [git:branch:cached]=red [git:dirty]=218 [git:stash]=cyan [host]=242 [path]=blue [prompt:continuation]=242 [prompt:error]=red [prompt:success]=magenta [user]=242 [user:root]=default [virtualenv]=242 )
  • TERM: export TERM=xterm-256color
  • Virtualenv: export VIRTUAL_ENV_DISABLE_PROMPT=12
  • Conda: export CONDA_CHANGEPS1=no
  • Detected frameworks: None

Other information

I have:

  • Tested with another terminal program and can reproduce the issue:
  • Followed the integration instructions for my framework

I don't think any of this applies, the problem is specific to Pure and it's clear from source code inspection.

Problem description

When you use a custom CONDA_ENVS_PATH conda shows by default the entire env path (and not just it's name) which usually is too large for a prompt. The usual trick is to configure env_prompt '({name})' in .condarc. But pure ignores this and just reads the name from CONDA_DEFAULT_ENV which is the entire path. Please add an option to only show the basename, I believe this is an important use case for a prompt that supports conda and, at the same time, tries to be non-invasive.

Reproduction steps

  1. Set CONDA_ENVS_PATH to /x/y/z
  2. Create a conda environment there
  3. Activate that environment

My .zshrc:

export CONDA_ENVS_PATH=~/Base/Venvs

fpath+=$HOME/.pure
autoload -U promptinit; promptinit
prompt pure

conda-init() {
    local base="/usr/local/Caskroom/miniconda/base"
    local conda_setup="$($base/bin/conda shell.zsh hook 2> /dev/null)"
    if [ $? -eq 0 ]; then
        eval "$conda_setup"
    else
        if [ -f "$base/etc/profile.d/conda.sh" ]; then
            . "$base/etc/profile.d/conda.sh"
        else
            export PATH="$/base/bin:$PATH"
        fi
    fi
}
conda-init
@memeplex
Copy link
Author

The minimal change I see here is from:

psvar[12]="${CONDA_DEFAULT_ENV//[$'\t\r\n']:t}"

to

psvar[12]="${${CONDA_DEFAULT_ENV:t}//[$'\t\r\n']:t}"

although this behaviour could be configurable.

@memeplex
Copy link
Author

Related to this: the base environment is always there and not very informative, really. Maybe a toggle to get a minimal conda prompt could control both aspects: use basename and hide the base environment.

@mafredri
Copy link
Collaborator

@memeplex unless there's a good use case for making this configurable, I think we'd prefer to stick with simply using the base name (:t). This would align with what we already do for regular virtualenvs. Feel free to submit a PR if you'd like 👍🏻.

@memeplex
Copy link
Author

Do you think base should be shown or not? It's pretty annoying given that it's visible all the time when one is not really thinking of the situation as "being inside an environment".

@mafredri
Copy link
Collaborator

I have no experience, nor do I use it, but is that the way conda is usually used, always active and (often) on base? If yes it probably makes sense to not show anything in that case 👍🏻.

@memeplex
Copy link
Author

always active and (often) on base?

Yes, it's usually sourced in your shell rc file so it's active and it prepends (base) to the prompt. I assume this is not extremely annoying for most conda users just because they tend to be more on the analytics/scientific side of things and are probably launching a shell from Anaconda Navigator in Windows, not having the terminal as a home base.

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

No branches or pull requests

2 participants