zsh: update prompt with current time when a command is started

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). I know you don’t need it constantly refreshed but it still gets the job done without needing a line for itself!

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

Leave a Comment