Ubuntu miniconda3环境下如何适配命令行?

Ubuntu miniconda3环境下如何适配命令行?

在 Ubuntu (WSL2) 中激活任何 miniconda3 环境时,命令行也会更改。在激活之前,我的命令行看起来像是我已经PS1.bashrc文件中定义了变量:

username@workingdirectory$

激活后,命令行变为:

(base)username@pc:/path/working/directory$

包括颜色的变化。

我希望命令行看起来与原始命令行类似(包括颜色),也许只在命令行末尾添加当前 conda 环境的名称。例如: username@workingdirectory (base)$

我已经将 设为changeps1in false.condarc但这仅从命令行中删除了 conda 环境,并且仍然更改了命令行的其余部分(包括颜色)。

有谁知道如何在 conda 环境中调整命令行以满足我的愿望?

按照@Edgar Magallan 的回答进行编辑:$HOME/miniconda3/bin/activate如下所示:

#!/bin/sh
_CONDA_ROOT="/home/username/miniconda3"
# Copyright (C) 2012 Anaconda, Inc
# SPDX-License-Identifier: BSD-3-Clause
\. "$_CONDA_ROOT/etc/profile.d/conda.sh" || return $?
conda activate "$@"

编辑2:我的文件中有两个地方conda.sh提到了PS1:

__conda_activate() {
if [ -n "${CONDA_PS1_BACKUP:+x}" ]; then
    # Handle transition from shell activated with conda <= 4.3 to a subsequent activation
    # after conda updated to >= 4.4. See issue #6173.
    PS1="$CONDA_PS1_BACKUP"
    \unset CONDA_PS1_BACKUP
fi
\local ask_conda
ask_conda="$(PS1="${PS1:-}" __conda_exe shell.posix "$@")" || \return
\eval "$ask_conda"
__conda_hashr
}

和:

if [ -z "${CONDA_SHLVL+x}" ]; then
   \export CONDA_SHLVL=0
   # In dev-mode CONDA_EXE is python.exe and on Windows
   # it is in a different relative location to condabin.
   if [ -n "${_CE_CONDA:+x}" ] && [ -n "${WINDIR+x}" ]; then
       PATH="$(\dirname "$CONDA_EXE")/condabin${PATH:+":${PATH}"}"
   else
       PATH="$(\dirname "$(\dirname "$CONDA_EXE")")/condabin${PATH:+":${PATH}"}"
   fi
   \export PATH

   # We're not allowing PS1 to be unbound. It must at least be set.
   # However, we're not exporting it, which can cause problems when starting a second shell
   # via a first shell (i.e. starting zsh from bash).
   if [ -z "${PS1+x}" ]; then
       PS1=
   fi
fi

相关内容