我知道我可以在我的zsh提示Exec中date命令。 然而,它显示了时间;看到当前的时间,我必须击中<return>,并得到一个新的提示与当前时间。

是否有配置zsh的提示不断更新自身每秒的方法吗?

有帮助吗?

解决方案

这将是....在标准的zsh提示(或bash,或其他外壳)不愉快。

我建议你会更好利用GNU屏幕。

屏幕可以具有一个状态线可显示时间。 下面是一个例子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

得到这个
RPROMPT='[%D{%L:%M:%S %p}]'

TMOUT=1

TRAPALRM() {
    zle reset-prompt
}

在TRAPALRM函数被调用每TMOUT秒(在此情况下1),在这里它执行一个提示刷新,并且这样做,直到命令开始执行(和它不与任何东西干扰你击球之前就提示输入输入)。

来源: http://www.zsh.org/mla/users/ 2007 / msg00944.html (这是从2007年!)

听起来像一个愉快请求给我。如果有任何它使不是显示被显示的提示当时间更有意义。

斯蒂芬森发布的技术。尝试这样的.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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top