I try the following:

clear-cmdline() {
    zle && zle kill-buffer
    sched +3 clear-cmdline
}
sched +3 clear-cmdline

After I run this code, I enter a few letters at prompt, and wait. Nothing happens. Unless I continue typing, then the command line gets cleared. How to obtain desired effect of just clear of the command line?

  • Hmm, per the docs "Commands are executed either immediately before a prompt, or while the shell's line editor is waiting for input." so in theory it should run while you're twiddling your thumbs... – thrig Sep 11 '16 at 15:07

It does work. It's just that the prompt is not redrawn until the next time you type something. Add a zle -R to redraw the prompt:

clear-cmdline() {
  zle && zle kill-buffer && zle -R
  sched +3 clear-cmdline
}
sched +3 clear-cmdline

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.