在 Zsh 上为每一行添加时间戳

Adding timestamp to each line on Zsh

我刚刚安装了 Sierra,想将 zsh 与 oh-my-zsh 和电源一起使用 shell...

我最终得到了这样一个终端:

但我想为每个输出添加一个时间戳。链接:

[14:23] acytryn ~ Projects %

有没有办法用 zsh 做到这一点?

将此添加到您的 ~/.zsh 文件的底部:

PROMPT='[%T] %n ~ %d %%'

我发现将时间实际添加到现有提示而不完全覆盖它更不会造成破坏。这使得它可以与任何现有主题一起使用而不会影响其样式。

将此添加到 .zshrc 文件的末尾。您可以键入命令 nano ~/.zshrc 以使用 nano:

对其进行编辑
PROMPT='%{$fg[yellow]%}[%D{%f/%m/%y} %D{%L:%M:%S}] '$PROMPT

我使用云主题,所以这给了我:

它保留了当前的主题。您还可以通过更改颜色甚至格式为时间戳添加一些样式。

确保通过键入以下内容重新加载您的 .zshrc 文件:

. ~/.zshrc

source ~/.zshrc

如果你想在右侧:

RPROMPT="[%D{%f/%m/%y} | %D{%L:%M:%S}]"

https://gist.github.com/zulhfreelancer/9c410cad5efa9c5f7c74cd0849765865

是的。 只需打开 ~/.zshrc 并在其末尾添加这一行(例如,在终端中使用 nano ~/.zshrc 命令):

PROMPT='%{$fg[yellow]%}[%*] '$PROMPT

你会得到这样的结果:

您可以更改 [%*] 部分以获得其他格式:

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