Zsh draws PS1 before each interactive command, so the prompt is the fastest place to show shell identity and working location. A prompt that includes the user, host, current directory, and prompt character makes it harder to run commands in the wrong terminal or path.
Prompt strings use Zsh percent escapes. PS1 and PROMPT name the same left prompt, and tokens such as %n, %m, %~, and %# expand to the username, short hostname, current directory, and normal-or-privileged prompt character when the prompt is displayed.
Persistent prompt changes for ordinary terminals belong in ~/.zshrc. Check the startup file before starting a new shell, and place the assignment after any theme, framework, or plugin block that also sets PS1 or PROMPT because the last assignment controls the visible prompt.
$ zsh -ic 'print -r -- "${ZDOTDIR:-$HOME}"'
/home/operator
If this command prints a path other than the home directory, edit $ZDOTDIR/.zshrc instead of ~/.zshrc.
$ cp -p ~/.zshrc ~/.zshrc.bak
Skip this command if ~/.zshrc does not exist yet. Use the matching file under $ZDOTDIR when the startup-file directory check showed a custom path.
$ vi ~/.zshrc
If ZDOTDIR is set, edit $ZDOTDIR/.zshrc instead of ~/.zshrc.
PS1='%n@%m:%~ %# '
| Token | Prompt segment |
|---|---|
| %n | Current username. |
| %m | Hostname up to the first dot. |
| %~ | Current directory, with the home directory shortened to ~. |
| %# | # for a privileged shell or a percent sign for a normal user. |
Use
PS1='%F{green}%n@%m%f:%~ %# '
instead when the user and host segment should be green. %F{green} starts green foreground text, and %f returns the prompt to the terminal default color.
$ zsh -n ~/.zshrc
No output from zsh -n means Zsh parsed the startup file without finding a syntax error.
$ zsh -ic 'print -P "$PS1"' operator@workstation:~ %
print -P expands prompt escapes without waiting for an interactive prompt to be drawn. The username, host, and path will match the local shell.
$ exec zsh
If the visible prompt still does not change, look for a later theme or prompt-framework line that resets PS1 or PROMPT after the custom assignment.