Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipe emacs shell output to a new buffer

Tags:

shell

emacs

For example, I want to be able to type something like:

$ git diff | tempbuffer

and have the diff opened in a new, unsaved buffer.

like image 805
Mary Rose Cook Avatar asked Dec 21 '11 13:12

Mary Rose Cook


2 Answers

If you use eshell you can redirect output to a buffer, e.g.

 print foo > #<buffer bar>

which creates a new buffer bar with the content 'foo'. For further details, see the Emacswiki at http://www.emacswiki.org/emacs/EshellRedirection.

like image 168
u-punkt Avatar answered Oct 06 '22 01:10

u-punkt


You can just use M-! -- it will run the command within the same cwd as your shell buffer, and output the results to a *Shell Command Output* buffer.

Note that if the results are brief, that buffer will not be raised and the output will be copied to the echo area; however the buffer is still used and available. C-hf shell-command RET has details of what constitutes "brief" output:

If the output is short enough to display in the echo area (determined by the variable max-mini-window-height if resize-mini-windows is non-nil), it is shown there. Otherwise, the buffer containing the output is displayed.

like image 31
phils Avatar answered Oct 06 '22 00:10

phils