I am new to programming and want to try to change the color of the user at my terminal for the beginning. Maybe add the host.

So looked up plenty of websites and youtube videos where they used a code like this:

export = [/u@h/W]/$

I copied this code to my .zshrc and .profile files.

But when I source these files I just get that my User is now "[/u@h/W]/$" and not my name@host.

Why does it not work for me?

I found this code which works but I am not able to modify:

DATE=$( date +"[%m-%d %H:%M]" )
PROMPT="${NEWLINE}%F{white}${DATE} %(!.%F{red}.%F{green})%n%F{white}@%m
%F{yellow}%F{reset}> "

Has someone an explanation for why the first way does not work but the second does?

  • 1
    What shell are you using - ie what does echo $SHELL show?
    – mmmmmm
    May 23, 2022 at 8:39
  • @mmmmmm echo $SHELL gives /bin/zsh, I modified the .zshrc file also
    – Andrea
    May 23, 2022 at 8:53
  • Please copy/paste the line from .zshrc you actually use there (export = [/u@h/W]/$ is syntactically not correct, I assume a copy/paste error).
    – nohillside
    May 23, 2022 at 9:31
  • Also, can you give an example of how you would like your prompt to look at at the end?
    – nohillside
    May 23, 2022 at 9:32

1 Answer 1


The simple answer as to why the two pieces of code give different results is that they are written for two different languages. The first is bash which was the default shell on OSX 10.3 up to 10.14. The second is zsh which is the current default shell. (Also the first is not correct code in any language there is a missing PS1 and there should be no spaces around =)

zsh will not read .bash_profile or .profile but just .zshrc

zsh is very well documented at https://zsh.sourceforge.io/ Prompt is documented here

The code given for the second is almost certainly not what you want as the DATE variable is set when the shell starts and you probably want the date and time when the prompt is run.

As a disclaimer I don't like most UNIX shells as the syntax is obscure to me as they were designed to let the user type as few characters as possible so I do not fully understand them so I would use non POSIX shells like fish which allows you to set the prompt from a web interface or understandable functions.

Simple example of the prompt are in the zsh introduction I would start there and build up. There is also zsh prompt generator web site that will allow you to play around with what can be done

However neither of those say anything about colours. For that see the zsh reference This shows that in the prompt %F{white} makes everything after it have white foreground colour. So you example would show white then green then red then white then yellow then reset to remove all colours.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .