1

I often execute shell commands via M-! and their output is then shown in the buffer *Shell Command Output*. How can I make this buffer display the end (rather than the beginning) so that I can see whether the shell command successfully terminated?

I saw here that when compiling via M-x compile, one can use (setq compilation-scroll-output t) to display the end of the compilation buffer. That behaviour would be great for *Shell Command Output*.

  • The compilation library can be used for many things beyond compiling a program, e.g., grep, or execute just any old program such as print the date. Here is an example: (let ((compilation-scroll-output t)) (compile "while :; do echo \"Hello-World\"; sleep 1; done")) – lawlist May 3 at 1:30
  • So you are essentially suggesting to rather work with M-x compile in this case? – Marius Hofert May 3 at 2:07
  • In a nutshell, "yes" that is my suggestion. It is certainly possible to put some time and effort into the function shell-command to make it behave as you desire. There are several variations of how that function operates depending upon the circumstances ... Someone may be inclined to write-up a solution for you ... this question; however, is (in my opinion) an exact duplicate of the linked thread ... which has a solution that may not be what you are looking for. – lawlist May 3 at 2:10
  • Thanks for your help. Interesting thoughts. At first, I thought that I want an answer to this, but then I realized that M-x compile in this case is also a bit more consistent in how I use it in other cases. Also, I often use M-! to create a new file (touch foo.txt) and there is no need to show the buffer in this case, for example (which would probably require a bit of work as you say). So, nice, thanks for pointing that out. – Marius Hofert May 3 at 2:18
2

Emacs 26.1 provides the shell-command-dont-erase-buffer option, if you set it to end-last-out, M-! moves the point to the end of the output, however, it won't delete the previous commands' outputs, unlike the default behavior.

(setq shell-command-dont-erase-buffer 'end-last-out)

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.