help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Redirecting the output of a commend in "shell" into a buffer


From: Emanuel Berg
Subject: Re: Redirecting the output of a commend in "shell" into a buffer
Date: Wed, 03 Sep 2014 19:49:45 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

C K Kashyap <address@hidden> writes:

> Hi, While using shell, is it possible to redirect
> output of commands into a buffer? Ofcourse, the shell
> buffer itself is editable and all but it would be
> nice if I could directly pipe the output of a command
> into a new buffer.

I combined some of my old stuff into the poor-man's
solution I spoke of earlier. If you have two shortcuts
- one to go to Emacs from the shell - and one to invoke
`pipe-buffer' (in Emacs), it is not that poor.

I could actually go to Emacs at the end of pipe-out...
but that wouldn't be perfect either, because in Emacs,
one would still have to invoke `pipe-buffer'. So, I'll
leave it double imperfect requiring two strokes. But
the stroke to go to Emacs should already be there, and
be habitually used - and, sudden (unasked for) shifts
between applications are a pain.

To be non-IPC I like this solution!

The reason for `do-show-file' is so that it won't ask
if you want the new version each time.

In Emacs:

(defun do-show-file (file)
  (interactive "f file")
  (progn
    (switch-to-buffer
     (find-file-noselect file t)) ; nowarn
    (revert-buffer t t nil)       ; ignore-auto noconfirm preserve-modes
    (message nil) ))

(defun pipe-buffer ()
  (interactive)
  (do-show-file "~/.emacs.d/piped-out.txt") )

In zsh:

#!/bin/zsh

pipe-out () {
    pipe_file=~/.emacs.d/piped-out.txt
    if (( $# )); then # usage: $ pipe-out `cmd`
        input=$*      #    or: $ pipe-out `cmd1` plain `cmd2` (etc.)
    else
        read -d \\0 input     # $ cmd | pipe-out
    fi
    echo $input >> $pipe_file
}

The code is here - fixes will be put there, as well:

http://user.it.uu.se/~embe8573/conf/emacs-init/files-my.el
http://user.it.uu.se/~embe8573/conf/emacs-init/linux-shell.el
http://user.it.uu.se/~embe8573/conf/.zsh/zsh-to-emacs

-- 
underground experts united


reply via email to

[Prev in Thread] Current Thread [Next in Thread]