Emacs Command
Instead of select-and-copy manually, you can also write a command and let it do the work for you:
;; Adapted from `comint-delete-output' (defun comint-copy-output () "Copy all output from interpreter since last input." (interactive) (let ((proc (get-buffer-process (current-buffer)))) (save-excursion (let ((pmark (progn (goto-char (process-mark proc)) (forward-line 0) (point-marker)))) (kill-new (buffer-substring comint-last-input-end pmark)))))) foo | bar
Your idea can also be achieved by a simple Shellshell script. It assumes Emacs server is running, if it is not, you can start it via the command server-start or run Emacs as a daemon.
#!/bin/bash cat /dev/stdin > /tmp/clip emacsclient --eval '(kill-new (my-file-contents "/tmp/clip"))' Becuase it's not easy to embedding Lisp code in Shellshell, my-file-contents is defined in Emacs.
(defun my-file-contents (file) (with-temp-buffer (insert-file-contents file) (buffer-string))) Now in shell, % foo | bar should do what you want (assumeingassuming bar is the Shellshell script and it is already in your PATH).
foo > /tmp/kill
In Eshell, you can save output to the kill ring by redirecting output to /dev/kill. You can do the similar in any shell:
- redirect output to
/tmp/kill - when the contents of
/tmp/killchanges, make Emacs copies the new contents to the kill ring
(notes that your Emacs should be compiled with support of watching filesystem, I guess it means (require 'filenotify) should return non-nil)
(defun save-to-kill-ring-if-changes (event) ;; (message "Event %S" event) (when (eq (cadr event) 'changed) (kill-new (my-file-contents "/tmp/kill")))) ;; Create /tmp/kill firstly (write-region "" nil "/tmp/kill") (file-notify-add-watch "/tmp/kill" '(change) 'save-to-kill-ring-if-changes) then in any shell, % foo > /tmp/kill should copy the output of foo to the kill ring.