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.

Steps to customize the Zsh prompt with PS1:

  1. Check the startup-file directory for the account.
    $ 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.

  2. Back up an existing interactive startup file before changing the prompt.
    $ 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.

  3. Open the interactive Zsh startup file.
    $ vi ~/.zshrc

    If ZDOTDIR is set, edit $ZDOTDIR/.zshrc instead of ~/.zshrc.

  4. Add a prompt assignment near the end of the file.
    ~/.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.

  5. Check the edited startup file for syntax errors.
    $ zsh -n ~/.zshrc

    No output from zsh -n means Zsh parsed the startup file without finding a syntax error.

  6. Preview the expanded prompt from a new interactive Zsh process.
    $ 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.

  7. Open a new terminal or replace the current shell after the syntax check passes.
    $ 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.