[ACCEPTED]-Constantly updated clock in zsh prompt?-zsh-zle
Note: I wrote this answer for a similar question, but seeing how this question has more views I think reposting my answer here would be useful.
This is in fact possible without resorting 7 to strange hacks. I've got this in my .zshrc
RPROMPT='[%D{%L:%M:%S %p}]'
TMOUT=1
TRAPALRM() {
zle reset-prompt
}
The 6 TRAPALRM function gets called every TMOUT 5 seconds (in this case 1), and here it performs 4 a prompt refresh, and does so until a command 3 starts execution (and it doesn't interfere 2 with anything you type on the prompt before 1 hitting enter).
Source: http://www.zsh.org/mla/users/2007/msg00944.html (It's from 2007!)
Sounds like a pleasant request to me. If 3 anything it makes more sense than showing 2 the time when the prompt was displayed.
Fortunately 1 Peter Stephenson posted a technique. Try something like this in .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
This would be .... unpleasant in a standard 8 zsh prompt (or bash, or other shells).
I 7 suggest you'd be better off using Gnu Screen.
Screen 6 can have a status line which can show the 5 time. Here's an example screenrc scroll down to "Red Hat Magazine 4 A guide to GNU Screen" to see the sample 3 (i'll reproduce that here) which will, when 2 screen is run, show the current time in 1 the lower right corner of the terminal:
~/.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
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.