1

This should be easy, right?

In zsh for instance, you could put this in your .zshrc:

reset_widget() tput reset
zle -N reset_widget
bindkey "^L" reset_widget

However, this resets the terminal, but requires you hit the enter key to reshow the prompt.

Changing the command to echo -ne '\n' | tput reset has no effect either.

Is there a way to reset the terminal using a keyboard shortcut, without having to hit the enter key afterwards to show the prompt?

  • This displays the prompt at the top of the screen for me following the reset under zsh -f. – thrig Nov 14 '16 at 15:05
  • @thrig - yes, but then none of my other scripts work :( – nbubis Nov 14 '16 at 16:37
  • Then you'll need to figure out what it is about your prompt (perhaps also hook functions) that is screwing things up. – thrig Nov 14 '16 at 16:55
2

thrig isn't seeing this because the act of resetting xyr terminal is causing a WINCH signal or some such, which causes ZLE to redisplay the prompt(s).

It does on the terminal that I am currently typing at, too. The terminal reset string emitted by tput reset includes the DECCOLM control sequence. This resets the terminal, from the 100 column mode that I have put it in, back to 80 column mode. The first time around, this does cause a WINCH signal because the terminal gets resized. The second time around it changes from 80 columns to 80 columns, which doesn't cause a WINCH. So I only see thrig's behaviour once on my terminal.

You aren't seeing this because that doesn't happen with your terminal and you've omitted telling ZLE that it needs to redisplay the prompt(s) as part of the widget:

reset_widget() { tput reset; builtin zle .redisplay; }

  • Like magic! So the solution to this is really shell dependent (i.e. for bash, we'll need to find another command?) – nbubis Nov 16 '16 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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