0

my .bash_profile is setting up my prompt like this

parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

export PS1="\u@\h \W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "

however, the result is that my prompt looks like this:

\u@\h \W\[\033[32m\]$(parse_git_branch)\[\033[00m\] $  

Just to get the username I tried the following so ANSI could be used in zsh

PROMPT=$'%{\u%}'

but the prompt became empty, like if \u was ignored.

How could ANSI be used as usual within zsh?

1
  • 1
    What you are showing are bash PS1 macro escapes, but according to the fine manual those are not what zsh uses, so it’s not unreasonable that they don't work. Jul 17, 2020 at 3:20

1 Answer 1

2

Zsh provides a very easy way to add color to your prompt; you don't need Escape codes.

PROMPT='%F{blue}%n%f %#'
  • %F = Sets foreground color defined in braces {}
  • %f = resets to default foreground color
  • %n = username

You can even access the 256 color pallet for your colors by specifying the number within the braces - %F{146} for “light steel blue“

For a detailed list of all the codes and what they do, see the official Zsh Documentation - Chapter 13 Visual Effects.

You must log in to answer this question.

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