83

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?

4 Answers 4

99

Use $'\n'

For example,

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

or

NEWLINE=$'\n'
PROMPT="firstline${NEWLINE}secondline "
5
  • 1
    Worked just like I needed it too.
    – Justin
    Commented May 12, 2015 at 17:09
  • 6
    using NEWLINE makes it a lot easier to edit the prompt
    – cmcginty
    Commented Dec 12, 2015 at 3:20
  • 2
    What's the difference between PS1 and PROMPT variable?
    – Didier A.
    Commented Feb 26, 2016 at 2:26
  • 3
    @DidierA. PROMPT, and PROMPT2-4 are aliases of PS1-4 respectively, except that the PROMPT aliases "[do] not exist when the shell initializes in sh or ksh emulation mode."
    – Victor
    Commented Oct 27, 2017 at 10:43
  • Awesome. That works. Thanks a lot, buddy.
    – JavaRunner
    Commented Jun 1, 2020 at 17:35
33
PS1="firstline
secondline "

or

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

Taken from FAQ, item 3.13

1
3

Like this (I know, looks awkward):

PS1="%~
 %> "
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

You must log in to answer this question.

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