Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constantly updated clock in zsh prompt?

I know that I can exec a date command in my zsh prompt. However, it shows the old time; to see the current time, I have to hit <return> and get a new prompt with the current time.

Is there a way to configure the zsh prompt to constantly update itself every second?

like image 816
anon Avatar asked Feb 02 '10 21:02

anon


1 Answers

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 to strange hacks. I've got this in my .zshrc

RPROMPT='[%D{%L:%M:%S %p}]'

TMOUT=1

TRAPALRM() {
    zle reset-prompt
}

The TRAPALRM function gets called every TMOUT seconds (in this case 1), and here it performs a prompt refresh, and does so until a command starts execution (and it doesn't interfere with anything you type on the prompt before hitting enter).

Source: http://www.zsh.org/mla/users/2007/msg00944.html (It's from 2007!)

like image 60
nitarshan Avatar answered Sep 22 '22 14:09

nitarshan