.. _intro_zsh_prompting:

Prompting
=========

The default prompt for :literal:`zsh` is:

.. code-block:: text
   :caption: Default host prompt
   :name: prompt_default

   phoenix% echo $PROMPT
   %m%# 

The :literal:`%m` stands for the short form of the current hostname, and the :literal:`%#` stands for a :literal:`%` or a :literal:`#`, depending on whether the shell is running as root or not. :literal:`zsh` supports many other control sequences in the :literal:`PROMPT` variable.

.. code-block:: text
   :caption: Path and history escapes
   :name: prompt_path_history

   % PROMPT='%/> '
   /u/pfalstad/etc/TeX/zsh>
   
   % PROMPT='%~> '   
   ~/etc/TeX/zsh> 
   
   % PROMPT='%h %~> '
   6 ~/etc/TeX/zsh> 

:literal:`%h` represents the number of current history event.

.. code-block:: text
   :caption: Host time user escapes
   :name: prompt_host_time_user

   % PROMPT='%h %~ %M> '
   10 ~/etc/TeX/zsh apple-gunkies.gnu.ai.mit.edu> 
   
   % PROMPT='%h %~ %m> '
   11 ~/etc/TeX/zsh apple-gunkies> 
   
   % PROMPT='%h %t> '
   12 6:11am> 
   
   % PROMPT='%n %w tty%l>'
   pfalstad Fri 24 ttyp0>

:literal:`PROMPT2` is used in multiline commands, like for-loops.  The :literal:`%_` escape sequence was made especially for this prompt.  It is replaced by the kind of command that is being entered.

.. code-block:: text
   :caption: Multiline PROMPT2 status
   :name: prompt_prompt2

   % PROMPT2='%_> '
   % for i in foo bar
   for>
   
   % echo 'hi
   quote>

Also available is the :literal:`RPROMPT` parameter. If this is set, the shell puts a prompt on the :emphasis:`right` side of the screen.

.. code-block:: text
   :caption: Right-side RPROMPT
   :name: prompt_rprompt

   % RPROMPT='%t'
   %                                                      6:14am
   
   % RPROMPT='%~'
   %                                               ~/etc/TeX/zsh
   
   % PROMPT='%l %T %m[%h] ' RPROMPT=' %~'
   p0 6:15 phoenix[5]                              ~/etc/TeX/zsh

These special escape sequences can also be used with the :literal:`-P` option to :literal:`print`:

.. code-block:: text
   :caption: print with -P escapes
   :name: prompt_print_p

   % print -P %h tty%l
   15 ttyp1

The :literal:`POSTEDIT` parameter is printed whenever the editor exits. This can be useful for termcap tricks.  To highlight the prompt and command line while leaving command output unhighlighted, try this:

.. code-block:: text
   :caption: POSTEDIT highlight trick
   :name: prompt_postedit

   % POSTEDIT=`echotc se`
   % PROMPT='%S%% '

This trick is mostly superseded by the zle_highlight array parameter.
