ano*_*non 8 zsh prompt zsh-zle
我知道我可以date
在zsh提示符下执行命令.然而,它显示了旧时代; 要查看当前时间,我必须按当前时间点击<return>
并获得新提示.
有没有办法配置zsh提示每秒不断更新自己?
nit*_*han 39
注意:我为类似的问题写了这个答案,但是看看这个问题如何有更多的观点,我认为在这里重新发布我的答案会很有用.
事实上,这可能不会诉诸于奇怪的黑客.我的.zshrc中有这个
RPROMPT='[%D{%L:%M:%S %p}]'
TMOUT=1
TRAPALRM() {
zle reset-prompt
}
Run Code Online (Sandbox Code Playgroud)
TRAPALRM函数每TMOUT秒调用一次(在本例中为1),此处执行快速刷新,直到命令开始执行为止(并且它不会干扰您在按Enter键之前在提示符上键入的任何内容).
资料来源:http://www.zsh.org/mla/users/2007/msg00944.html(从2007年开始!)
小智 8
这将是......在标准的zsh提示符(或bash或其他shell)中令人不快.
我建议你最好使用Gnu Screen.
屏幕可以有一个状态行,可以显示时间. 这是一个示例screenrc向下滚动到"红帽杂志GNU屏幕指南"以查看示例(我将在此处重现),当屏幕运行时,将显示终端右下角的当前时间:
〜/ .screenrc
hardstatus alwayslastline hardstatus string '%{= kG}[ %{G}%H %{g}][%= %{=kw}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B}%Y-%m-%d %{W}%c %{g}]' # Default screens screen -t shell1 0 screen -t shell2 1
http://www.gnu.org/software/screen/
听起来对我来说是一个愉快的要求.如果有什么比显示提示显示的时间更有意义.
幸运的是,彼得斯蒂芬森发布了一项技术.在.zshrc中尝试这样的事情:
PROMPT="[%T] %n@%M %~ %# "
schedprompt() {
emulate -L zsh
zmodload -i zsh/sched
# Remove existing event, so that multiple calls to
# "schedprompt" work OK. (You could put one in precmd to push
# the timer 30 seconds into the future, for example.)
integer i=${"${(@)zsh_scheduled_events#*:*:}"[(I)schedprompt]}
(( i )) && sched -$i
# Test that zle is running before calling the widget (recommended
# to avoid error messages).
# Otherwise it updates on entry to zle, so there's no loss.
zle && zle reset-prompt
# This ensures we're not too far off the start of the minute
sched +30 schedprompt
}
schedprompt
Run Code Online (Sandbox Code Playgroud)