0 votes
in Linux by
How can you use the Zsh prompt expansion to customize your command prompt?

1 Answer

0 votes
by

Zsh prompt expansion allows customization of the command prompt. To do this, you need to set the ‘PROMPT’ variable in your .zshrc file. The value assigned to PROMPT is what appears as your command prompt. Zsh supports a variety of special characters for prompt expansion. For instance, ‘%m’ displays machine’s hostname and ‘%~’ shows the current working directory. You can also add colors using ‘%F{color}’ before the character and ‘%f’ after it. If you want to display username, use ‘%n’. A simple example would be:

PROMPT='%F{green}%n%f@%m %~ %# '

This will show username in green followed by ‘@’, hostname, current directory, and finally a ‘#’ or ‘%’ depending on whether you are root or not.

...