zshでコマンドプロンプトにdd / mm / yyを設定するには?

zshでコマンドプロンプトにdd / mm / yyを設定するには?

私はoh-my-zshではなくzshを使用しており、カスタムコマンドプロンプトが欲しいです。

現在、ホスト名と%のみがコマンドプロンプトで提供されています。

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

私がやりたいことは――

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

この問題にどのように対処する必要がありますか?

man zshmiscで手がかりを見た

特にプロンプ​​トシーケンスの拡張で

プロンプトシーケンスの拡張プロンプトシーケンスは特別な形式の拡張を経ます。このタイプの拡張は、組み込み印刷機能の-Pオプションを使用しても可能です。

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

拡張。 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

「!!」で表現されます。

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

単一文字ですが、その一部は「%」とシーケンスの次の文字の間に現れる必要があるオプションの整数引数を使用します。条件付き拡張を提供するために、より複雑なエスケープシーケンスを使用できます。

単純プロンプトエスケープ文字%% `%'。

   %)     A `)'.

ログイン情報%lユーザーログイン行(tty)、/ dev / tty 'がなく、/dev/' prefix. If the name starts withプレフィックスが削除されました。

   %M     The full machine hostname.

%m最初の%'までの.'. An integer may follow the ホスト名、必要なホスト名コンポーネントの数を指定します。負の整数の場合、ホスト名の最後の部分が表示されます。

   %n     $USERNAME.

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

そうでない場合、シェルの状態は %#A #' if the shell is running with privileges, a%' です。この目的のために%(!.#.%%)'. The definition of「権限」に対応するのは、有効ユーザーIDが0である場合、またはPOSIX.1e機能がサポートされている場合に有効または継承可能な機能ベクトルに提案された1つ以上の機能です。

   %?     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

整数が与えられると、多くの文字列が印刷されます。ゼロまたは負の数または整数がない場合は、できるだけ多くの値を印刷することを意味します。これは、連続行のためにPS2をプロンプトし、XTRACEオプションを使用してデバッグのためにPS4をプロンプトするときに最も便利です。後者の場合、非対話式でも機能します。

%^ リバースパーサーの状態です。文字列の順序以外は「%_」と同じです。 RPS2で一般的に使用されます。

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

表示する作業ディレクトリは、ゼロがフルパスを意味します。負の整数は先行コンポーネントを指定します。つまり、%-1dは最初のコンポーネントを指定します。

日付と時刻%D yy-mm-dd形式の日付。

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

私はいくつかの方法を試しましたが、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 $

更新 - 非常に近い -

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

知ることを期待

zsh バージョン 5.2 の実行

ベストアンサー1

フォーマットの日付/時刻部分には、DD/MM/YY HH:MM:SS次のものを使用できます。

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

引用する

%D{string}:文字列形式を指定するには、strftime関数を使用してください。 ...

おすすめ記事