82

I'm trying to setup a multiple line PS1, for zsh, but \n doesn't was parsed by zsh,

PS1="%~\n %> "

How should I set it up?

daisy
  • 54,555

4 Answers4

97

Use $'\n'

For example,

PROMPT="firstline"$'\n'"secondline "

or

NEWLINE=$'\n'
PROMPT="firstline${NEWLINE}secondline "
Anthon
  • 79,293
n5c
  • 1,071
33
PS1="firstline
secondline "

or

PS1=$'Hi Joe,\nwhat now?%# '

Taken from FAQ, item 3.13

int
  • 574
  • 2
    This can cause problem. See the link. https://superuser.com/questions/382503/how-can-i-put-a-newline-in-my-zsh-prompt-without-causing-terminal-redraw-issues – kirin Feb 02 '19 at 13:33
3

I know this is an old question, but I was looking for this as well. If you load prompinit (autoload -Uz promptinit && promptinit) you get the option for free: $prompt_newline which is $'\n%{\r%}'.

On a Debian system you can find the source code in /usr/share/zsh/functions/Prompts/promptinit and/or https://github.com/zsh-users/zsh/blob/master/Functions/Prompts/promptinit

3

Like this (I know, looks awkward):

PS1="%~
 %> "
Emanuel Berg
  • 6,903
  • 8
  • 44
  • 65