Marcin Borkowski has a really handy tip that explains something that I didn’t know. I’m a big fan of Eshell and usually reach for it first when I need a shell. One long standing problem I’ve had with it is clearing the screen. Doing a clear
, as you would in other shells, doesn’t work. You can do a clear
in Eshell but it doesn’t do what your expecting.
To deal with this, I long ago wrote a bit of code that lets me use the universal argument to clear the screen when I finish with an Eshell session. I like to run Eshell in full screen, which I invoke with Hyper+e, so the following lets me start and stop an Eshell session optionally clearing the history (by quitting Eshell) when I exit.
(global-set-key (kbd "H-e") (lambda (exit) "Bring up a full-screen eshell or restore previous config. With a prefix argument, exit eshell before restoring previous config." (interactive "P") (if (string= "eshell-mode" major-mode) (progn (when exit (insert "exit") (eshell-send-input)) (jump-to-register :eshell-fullscreen)) (progn (window-configuration-to-register :eshell-fullscreen) (eshell) (delete-other-windows)))))
The result of that is that Eshell forgets its previous content when I exit it with the universal argument.
Borkowski’s tip is really simple. If you want to clear the Eshell buffer, you can do it by specifying clear
with an argument. Thus, clear t
will clear the Eshell buffer in the way you’re expecting. That’s very nice and good to know.