0

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?

1 Answers1

1

Per usual, I discovered the answer within minutes of posting my question, even though I've already spent hours trying to figure it out. The answer is, yes, zsh is apparently quite different. This post is what led me to the answer.

precmd() {
       psvar[1]=$CONDA_DEFAULT_ENV:t
}
PS1=$'\n'"%F{blue}[ %F{green}%n%F{white}@%F{yellow}%m%F{white}:%F{cyan}%d %F{blue}]"$'\n'
PS1+="%F{cyan}(%1v) %F{white}:> "

See also the $CONDA_DEFAULT_ENV:t (from csh) which expands to the tail of the path stored in $CONDA_DEFAULT_ENV and is a more efficient and more reliable way than having to spawn a new process that executes an external basename utility and read its output through a pipe like $(basename $CONDA_DEFAULT_ENV) (which should have been "$(basename -- "$CONDA_DEFAULT_ENV")") does.