The first step is to disable the default conda prompt modifier by running conda config --set changeps1 false
as they already mentioned.
Next, add the following to your .zshrc
:
# Determines prompt modifier if and when a conda environment is active
precmd_conda_info() {
if [[ -n $CONDA_PREFIX ]]; then
if [[ $(basename $CONDA_PREFIX) == "miniconda3" ]]; then
# Without this, it would display conda version
CONDA_ENV="(base) "
else
# For all environments that aren't (base)
CONDA_ENV="($(basename $CONDA_PREFIX)) "
fi
# When no conda environment is active, don't show anything
else
CONDA_ENV=""
fi
}
# Run the previously defined function before each prompt
precmd_functions+=( precmd_conda_info )
# Allow substitutions and expansions in the prompt
setopt prompt_subst
PROMPT='%F{cyan}$CONDA_ENV%f%F{green}%n%f %B%F{blue}%1~%f%b $ '
With this, the conda environment is shown before the rest of the prompt, inside parentheses, and in cyan.
If you want it to appear bold, enclose that portion in %B and %b:
PROMPT='%B%F{cyan}$CONDA_ENV%b%f%F{green}%n%f %B%F{blue}%1~%f%b $ '
If you want to use more colours, check whether your terminal supports it by running echo $TERM
. If it returns xterm-256color
, you can replace the colours in curly brackets by values from 0 to 255. You can check out the colours here.
PS- Those using anaconda instead of miniconda will need to replace miniconda3
with anaconda3
in the code.