Como definir dd / mm / aa para prompt de comando em zsh?

0

Estou em zsh (não usando oh-my-zsh) e quero ter um prompt de comando personalizado.

Atualmente, apenas fornece o nome do host e% como prompt de comando -

[code]
think-debian% hostname
think-debian
[/code]

o que eu quero fazer é ter -

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

como eu gerencio isso?

Eu vejo a dica no homem zshmisc

e especificamente na EXPANSÃO DE SEQUÊNCIAS PROMPT

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.

   %d
   %/     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.

   %t
   %@     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.

Eu tentei algumas maneiras, mas não consegui entrar em dd / mês / aa -

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 $

Atualização - chegou bem perto com -

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

Ansioso para saber

Executando a versão 5.2 do zsh

    
por shirish 19.12.2016 / 08:21

1 resposta

1

Para a parte de data / hora no formato DD/MM/YY HH:MM:SS , você pode usar o seguinte:

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

Referência:

%D{string} : string é formatada usando a função strftime. ...

    
por 19.12.2016 / 11:35