Recently I updated my MacOS to Catalina. Now the default shell is zsh, i could like revert it to bash but I thought to play along. Now I came across a problem while wanting to customize my Command Prompt.
In $HOME/.zshenv
I declared;
export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
in that folder I have the .zshrc
file. It contains the part of the conda initialization.
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/finn/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/finn/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/finn/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/finn/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
But more importantly I source this prompt.sh
file:
function promptcmd () {
local blue="{33}";
local cyan="{87}";
local orange="{160}";
local pink="{200}";
local white="{15}";
local yellow="{226}";
# Set the terminal title and prompt.
PROMPT=""; # working directory base name
PROMPT+="%B"; # all bold
PROMPT+="%F${pink}%n%f"; # username
PROMPT+="%F${yellow}@%f"; # at
PROMPT+="%F${orange}%M%f"; # hostname
PROMPT+="%F${white} in %f"; # in
PROMPT+="%F${blue}%~%f"; # directory
PROMPT+="%F${white} \$ %f%b";
if [[ $CONDA_DEFAULT_ENV != "base" ]]; then
RPROMPT="%F${cyan}($CONDA_DEFAULT_ENV)%f";
fi;
}
promptcmd
The PROMPT
part works perfectly fine. But the part where I'd like to display my Anaconda Environment on the right hand side, it doesn't. The problem is that the Environment Variable $CONDA_DEFAULT_ENV
is read incorrectly. If I were to just display the Variable in the prompt (without the if
statement) I see how it always stays (base)
, even though I typed conda activate my_env
, then entered echo $CONDA_DEFAULT_ENV
and it returned my_env
.
Is .zshrc
not rereading the Environment Variables?
EDIT:
You are only calling
promptcmd
once; you want to defineprecmd
instead (or allpromptcmd
from insidepromptcmd
) so that your prompt is redefined just before it is displayed every time.
chedner's commment helped; Just by renaming the promptcmd
function, it at first somehow worked. The RPROMPT
is empty until I conda activate my_env
, then it says (my_env)
. But then some weird behavior followed, which I can only show you: