【发布时间】:2017-02-25 20:35:30
【问题描述】:
我刚刚安装了 Sierra,想将 zsh 与 oh-my-zsh 和 power shell 一起使用...
我最终得到了这样的终端:
但我想为每个输出添加一个时间戳。东西链接:
[14:23] acytryn ~ Projects %
有没有办法用 zsh 做到这一点?
【问题讨论】:
标签: macos terminal zsh oh-my-zsh
我刚刚安装了 Sierra,想将 zsh 与 oh-my-zsh 和 power shell 一起使用...
我最终得到了这样的终端:
但我想为每个输出添加一个时间戳。东西链接:
[14:23] acytryn ~ Projects %
有没有办法用 zsh 做到这一点?
【问题讨论】:
标签: macos terminal zsh oh-my-zsh
【讨论】:
PROMPT='%{$fg[yellow]%}[%D{%T}] '$PROMPT
} %D{部分。所以你会有PROMPT='%{$fg[yellow]%}[%D{%f/%m/%y %L:%M:%S}] '$PROMPT。这种方式对我有用。
如果你想要它在右侧:
RPROMPT="[%D{%f/%m/%y} | %D{%L:%M:%S}]"
https://gist.github.com/zulhfreelancer/9c410cad5efa9c5f7c74cd0849765865
【讨论】:
将此添加到 ~/.zsh 文件的底部:
PROMPT='[%T] %n ~ %d %%'
【讨论】:
PROMPT='[%T] %n ~ %d %%'”来试试?
source ~/.zshrc 但没有任何改变。我正在使用 powerline-shell,我不知道这是否会以某种方式干扰。此外,直接将其粘贴到提示中没有输出
precmd 函数在显示之前动态设置PROMPT 的值。您需要按照github.com/banga/powerline-shell 的说明修改您的提示。
是的。
只需打开您的 ~/.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.
【讨论】: