Zsh and the Various Prompts

The zsh prompts are extremely configurable. In fact, the zsh prompts get their own type of expansion. (If you would like to use prompt expansion on other strings, simply use the -P argument to zsh's print builtin.)

The primary zsh prompt string is contained in the shell variable PROMPT. This variable is also known as PS1. (They are the exact same - assigning to one sets the other.)

Before zsh actually displays them, the prompts are first subjected to parameter expansion, command substitution, and arithmetic expansion. (But ONLY if the PROMPT_SUBST shell option is turned on)

Customizing the Prompt(s)

At some point, everyone seems to want to customize their prompt. There are over 40 special escape sequences in zsh that allow you to control what kind of information is displayed in your prompt(s).

As with most shells, zsh lets you display various pieces of information in your prompt. The current time, date, host information, and current directory are just simple examples.

Zsh goes much further. It allows you to truncate your prompt so that it only takes up a certain amount of space on the command line. It also provides many different formatting options for each piece of information it can display. It can print the time and date with strftime(3) functionality. Zsh supports 'conditional expressions' within prompts. This means that zsh will display different things in your prompt(s) based on certain conditions.

In the next few sections, we will cover all of the facilities available for you to customize your prompt(s) with.