I am on zsh (not using oh-my-zsh) and want to have a custom command prompt.

Currently it just gives the hostname and % as command prompt -

think-debian% hostname

what I want to do is to have -

[username/userid@hostname] - [pwd]-[ DD/MM/YY local time in hh:mm:ss] $

how do I manage that ?

I do see the clue in man zshmisc


EXPANSION OF PROMPT SEQUENCES Prompt sequences undergo a special form of expansion. This type of expansion is also available using the -P option to the print builtin.

   If the PROMPT_SUBST option is set, the prompt string is first subjected to parameter expansion, command substitution and arithmetic 

expansion. See zshexpn(1).

   Certain escape sequences may be recognised in the prompt string.

   If  the  PROMPT_BANG  option is set, a `!' in the prompt is replaced by the current history event number.  A literal `!' may then

be represented as `!!'.

   If the PROMPT_PERCENT option is set, certain escape sequences that start with `%' are expanded.  Many escapes  are  followed  by  a 

single character, although some of these take an optional integer argument that should appear between the `%' and the next character of the sequence. More complicated escape sequences are available to provide conditional expansion.

SIMPLE PROMPT ESCAPES Special characters %% A `%'.

   %)     A `)'.

Login information %l The line (tty) the user is logged in on, without /dev/' prefix. If the name starts with/dev/tty', that prefix is stripped.

   %M     The full machine hostname.

%m The hostname up to the first .'. An integer may follow the %' to specify how many components of the hostname are desired. With a negative integer, trailing components of the hostname are shown.

   %n     $USERNAME.

   %y     The line (tty) the user is logged in on, without `/dev/' prefix.  This does not treat `/dev/tty' names specially.

Shell state %# A #' if the shell is running with privileges, a%' if not. Equivalent to %(!.#.%%)'. The definition ofprivileged', for these purposes, is that either the effective user ID is zero, or, if POSIX.1e capabilities are supported, that at least one capability is raised in either the Effective or Inheritable capability vectors.

   %?     The return status of the last command executed just before the prompt.

   %_     The  status  of  the parser, i.e. the shell constructs (like `if' and `for') that have been started on the command line. If

given an integer number that many strings will be printed; zero or negative or no integer means print as many as there are. This is most useful in prompts PS2 for continuation lines and PS4 for debugging with the XTRACE option; in the latter case it will also work non-interactively.

%^ The status of the parser in reverse. This is the same as `%_' other than the order of strings. It is often used in RPS2.

   %/     Current working directory.  If an integer follows the `%', it specifies a number of  trailing  components  of  the  current 

working directory to show; zero means the whole path. A negative integer specifies leading components, i.e. %-1d specifies the first component.

Date and time %D The date in yy-mm-dd format.

   %T     Current time of day, in 24-hour format.

   %@     Current time of day, in 12-hour, am/pm format.

   %*     Current time of day in 24-hour format, with seconds.

   %w     The date in day-dd format.

   %W     The date in mm/dd/yy format.

I tried quite a few ways but unable to get it in dd/Month/yy -

think-debian%PS1=%n@%m-%/\ %D\ %*\ $

shirish@think-debian-/home/shirish 16-12-19 12:33:27 $ PS1=%n@%m-%/\ %W\ %*\ $

shirish@think-debian-/home/shirish 12/19/16 12:33:55 $

Update - Have come very close with -

$PS1=%n@%m-%/\ %D{%d/%m/%y}\ %*\ $
 shirish@think-debian-/home/shirish 19/12/16 17:31:09 $ 

Looking forward to know

Running zsh version 5.2

1 Answer 1


For the date/time part in the format DD/MM/YY HH:MM:SS, you can use the following:

%D{%d/%m/%y %H:%M:%S}


%D{string}: string is formatted using the strftime function. ...

  • 1
    you are very near, just near a bit more, if you can wing it, wing it please.
    – shirish
    Dec 19, 2016 at 12:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .