Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Constantly updated clock in prompt

On Dec 10,  1:10am, Samuel Laverdière wrote:
} I found a way to update the time in my prompt, but it breaks the completion
} menu (items in the menu become invisible). I found the solution on the
} Internet, so I know other people are looking for the same thing (updated
} time in prompt), but I can't believe they all learn to live with the bugs I
} have to deal with. Does it happen to anyone else? Is there a way to avoid
} it?

The menu-select widget isn't prepared to have its display interrupted by
reset-prompt (menu-select is in the separate zsh/complist module, and
IIRC reset-prompt was added after that module was written).

I keep the time in the window title bar instead of the prompt, and update
it with

	print -nP "%{$top${*:-%m.%l:%2c - %t}$back%}"

(where $top and $back are the terminal-specific control codes update the
title bar).

You could easily do this with, say, the upper right corner of the screen
instead of the title bar.

(In more detail, I update the title bar in my precmd hook, and set the
initial TMOUT to 10 minutes so the title bar only starts updating itself
when I've been idle for a while.)

Other suggestions:

Create TRAPALRM before you assign TMOUT, or you're asking for a race to
occur where the signal arrives before it is trapped.

If you're only tracking time to the minute (%T), use TMOUT=10 so there
are fewer interrupts.  Or to be really minimalist:

    zmodload zsh/datetime
      print -nP "%{$top${*:-%m.%l:%2c - %t}$back%}"	# or whatever
      TMOUT=$(( EPOCHSECONDS % 60 ))

One wakeup per minute, exactly on the minute!

Aside for zsh-workers:


    TRAPALRM() { zle reset-prompt; zle redisplay }

(or pretty much any zle thing after reset-prompt) I get:

    Src/Zle/zle_thingy.c:660: line metafied

However, that does NOT happen if I do

    TRAPALRM() { zle -I; zle reset-prompt; zle redisplay }

Whatever that bug is, has no effect on the menu-select redraw problem.

Messages sorted by: Reverse Date, Date, Thread, Author