mamba-org / mamba

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

PS1 is lost during activation if it isn't exported #2659

Open chrisburr opened 1 year ago

chrisburr commented 1 year ago

Troubleshooting docs

How did you install Mamba?

Micromamba

Search tried in issue tracker

PS1

Latest version of Mamba

Tried in Conda?

Not applicable

Describe your issue

On some systems PS1 isn't exported and is only set as a shell variable. When calling micromamba shell hook activate -s bash this results in the PS1 prompt being lost when using micromamba 1.4.6. When using micromamba 1.4.2 there isn't any issue.

This issue can be reproduced by running the following two lines prior to activation:

unset PS1
PS1='\s-\v\$ '

When comparing the output of micromamba shell hook activate -s bash I see the significat difference is at the end:

@@ -102,3 +95,12 @@ if [ -n "${BASH_VERSION:+x}" ]; then
   complete -o default -F _umamba_bash_completions micromamba
 fi

+PS1='(base) '
+export PATH='/cvmfs/lhcb.cern.ch/lhcbdirac/versions/v11.0.13-1688394803/Linux-x86_64/bin:/cvmfs/lhcb.cern.ch/lhcbdirac/versions/v11.0.13-1688394803/Linux-x86_64/condabin:/afs/cern.ch/user/c/cburr/scripts:/cvmfs/lhcb.cern.ch/lib/bin/x86_64-centos7:/cvmfs/lhcb.cern.ch/lib/bin/Linux-x86_64:/cvmfs/lhcb.cern.ch/lib/bin:/cvmfs/lhcb.cern.ch/lib/var/lib/LbEnv/2850/stable/linux-64/bin:/usr/sue/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/opt/puppetlabs/bin'
+export CONDA_PREFIX='/cvmfs/lhcb.cern.ch/lhcbdirac/versions/v11.0.13-1688394803/Linux-x86_64'
+export CONDA_SHLVL='1'
+export CONDA_DEFAULT_ENV='base'
+export CONDA_PROMPT_MODIFIER='(base) '
+. "/cvmfs/lhcb.cern.ch/lhcbdirac/versions/v11.0.13-1688394803/Linux-x86_64/etc/conda/activate.d/activate_condor.sh"
+. "/cvmfs/lhcb.cern.ch/lhcbdirac/versions/v11.0.13-1688394803/Linux-x86_64/etc/conda/activate.d/libglib_activate.sh"
+. "/cvmfs/lhcb.cern.ch/lhcbdirac/versions/v11.0.13-1688394803/Linux-x86_64/etc/conda/activate.d/libxml2_activate.sh"

I'm fairly certain the issue comes from here: https://github.com/mamba-org/mamba/blob/c926198af82a6796c67ae5eee89d903556286588/libmamba/src/core/activation.cpp#L806-L826

mamba info / micromamba info

libmamba version : 1.4.6
     micromamba version : 1.4.6
           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 : /cvmfs/lhcb.cern.ch/lhcbdirac/versions/v11.0.13-1688394803/Linux-x86_64/envs
          package cache : /cvmfs/lhcb.cern.ch/lhcbdirac/versions/v11.0.13-1688394803/Linux-x86_64/pkgs
                          /afs/cern.ch/user/c/cburr/.mamba/pkgs
            environment : None (not found)
           env location : -
      user config files : /afs/cern.ch/user/c/cburr/.mambarc
 populated config files : /cvmfs/lhcb.cern.ch/lhcbdirac/versions/v11.0.13-1688394803/Linux-x86_64/.condarc
       virtual packages : __unix=0=0
                          __linux=3.10.0=0
                          __glibc=2.17=0
                          __archspec=1=x86_64
               channels : https://conda.anaconda.org/diracgrid/linux-64
                          https://conda.anaconda.org/diracgrid/noarch
                          https://conda.anaconda.org/conda-forge/linux-64
                          https://conda.anaconda.org/conda-forge/noarch
       base environment : /cvmfs/lhcb.cern.ch/lhcbdirac/versions/v11.0.13-1688394803/Linux-x86_64
               platform : linux-64

Logs

No response

environment.yml

No response

~/.condarc

No response

jonashaag commented 1 year ago

Any ideas how to fix this?

chrisburr commented 1 year ago

I'm not in a position to be able to test this out but I think the only option is something to the effect of:

 PosixActivator::update_prompt(const std::string& conda_prompt_modifier) 
 { 
-    std::string ps1 = (m_env.find("PS1") != m_env.end()) ? m_env["PS1"] : ""; 
+    std::string ps1 = "${PS1:-}"; 
jonashaag commented 1 year ago

Yes i think that makes sense