I found this post that perfectly describes the problem I'm having. The only difference is that I'm using zsh. When I escape the '$' as @filbranden described, it just prints the $(basename $CONDA_DEFAULT_ENV)
to the prompt. The following sort of works, but doesn't update with activation as @johnchase described originally.
PS1=$'\n'"%F{blue}[ %F{green}%n%F{white}@%F{yellow}%m%F{white}:%F{cyan}%d %F{blue}]"$'\n'
PS1+="%F{cyan}("$(basename $CONDA_DEFAULT_ENV)") %F{white}:> "
Gives me:
(base) :> conda activate datasci
[ downtime@samurai:/home/downtime ]
(base) :> [insert]
[ downtime@samurai:/home/downtime ]
(base) :> echo $CONDA_DEFAULT_ENV [insert]
datasci
And if I change to :
PS1=$'\n'"%F{blue}[ %F{green}%n%F{white}@%F{yellow}%m%F{white}:%F{cyan}%d %F{blue}]"$'\n'
PS1+="%F{cyan}(\$(basename \$CONDA_DEFAULT_ENV)) %F{white}:> "
I get:
[ downtime@samurai:/home/downtime ]
($(basename $CONDA_DEFAULT_ENV)) :>
Does zsh handle PS1 so differently? What am I missing?
set -o promptsubst
for the parameter expansions and command substitutions to be performed upon prompt expansion like inksh
/bash
, but using$psvar
instead is generally safer and more reliable. See my recent answer to similar question here – Stéphane Chazelas Feb 06 '22 at 14:13