-1

So, in my zshrc I have a blue prompt, and when the root user is used, it uses a version of the same prompt with the word blue changed to red

if [ $UID = 0 ]
then
     export PS1="%B%F{red}[ %n@%m ]%f%b %F{white}:%f %F{yellow}%~%f %B%F{cyan}>%b%f "
     export RPS1="%B%F{cyan}<%b%f "$(date +"%d/%m/%y ~ %H:%M:%S")""
else 
     export PS1="%B%F{blue}[ %n@%m ]%f%b %F{white}:%f %F{yellow}%~%f %B%F{cyan}>%b%f "
     export RPS1="%B%F{cyan}<%b%f "$(date +"%d/%m/%y ~ %H:%M:%S")""
fi

I've done it like this for some time, but is it possible to just replace the word blue in PS1="%B%F{blue}..... with red? Or, the other way around?

Andy3153
  • 33
  • 4

1 Answers1

1

Use a separate parameter to store you choice of color, then use that in the definition of PS1.

if [ $UID = 0 ]; then
    color=red
else
    color=blue
fi

PS1="%B%F{$color}[ %n@%m ]%f%b %F{white}:%f %F{yellow}%~%f %B%F{cyan}>%b%f "
RPS1="%B%F{cyan}<%b%f %D{%d/%m/%y ~ %T}"  # You don't need to call date
chepner
  • 497,756
  • 71
  • 530
  • 681