mamba-org / mamba

The Fast Cross-Platform Package Manager
https://mamba.readthedocs.io
BSD 3-Clause "New" or "Revised" License
6.53k stars 342 forks source link

Environment names containing '.' get cut out on the shell prompt #2680

Open flowln opened 11 months ago

flowln commented 11 months ago

Troubleshooting docs

How did you install Mamba?

Micromamba

Search tried in issue tracker

dot,cut,prompt

Latest version of Mamba

Tried in Conda?

I didn't try

Describe your issue

When an environment is active in a shell session, it shows up in that shell's prompt. However, when that environments name contains a dot character, it gets cut of.

For instance, here I have an environment called pyside2_5.13, which when active, shows up like that:

Fish: environment name shows up as pyside5_5 instead of the correct pyside5_5.13

Bash: environment name shows up as pyside5_5 instead of the correct pyside5_5.13

Possibly caused by this use of .stem(), though it's only a guess of mine: https://github.com/mamba-org/mamba/blob/b3b6cd6d07f8badf49f7f746e624a23d024baba8/libmamba/src/core/activation.cpp#L199

mamba info / micromamba info

libmamba version : 1.4.9
     micromamba version : 1.4.9
           curl version : libcurl/7.88.1 OpenSSL/3.1.1 zlib/1.2.13 zstd/1.5.2 libssh2/1.11.0 nghttp2/1.52.0
     libarchive version : libarchive 3.6.2 zlib/1.2.13 bz2lib/1.0.8 libzstd/1.5.2
       envs directories : /home/low/micromamba/envs
          package cache : /home/low/micromamba/pkgs
                          /home/low/.mamba/pkgs
            environment : pyside2_5.13 (active)
           env location : /home/low/micromamba/envs/pyside2_5.13
      user config files : /home/low/.mambarc
 populated config files : /home/low/.mambarc
       virtual packages : __unix=0=0
                          __linux=6.3.1=0
                          __glibc=2.37=0
                          __archspec=1=x86_64
               channels : https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://conda.anaconda.org/nodefaults/linux-64
                          https://conda.anaconda.org/nodefaults/noarch
       base environment : /home/low/micromamba
               platform : linux-64

Logs

No response

environment.yml

No response

~/.condarc

No response

SamGilmourQC commented 4 months ago

I'm running into the same issue. A workaround is to define your own shell prompt using basename $CONDA_PREFIX (rather than $CONDA_DEFAULT_ENV, which is the variable usually used).

E.g. in Zsh, without a shell theme, you can add this to .zshrc:

show_virtual_env() {
  if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
    echo "($(basename $CONDA_PREFIX)) "
  fi
}
PS1='$(show_virtual_env)'$PS1

With a theme that supports conda/mamba environments, you can fish around for its usage of $CONDA_DEFAULT_ENV and modify it to basename $CONDA_PREFIX.