The command
emacs -nw foo -f org-mode
opens the file foo
in emacs
in org-mode
.
Now, suppose that the filename foo
is the output of a script. How could I pipe to my command?
So, I'm trying to get something like
echo foo | emacs -nw {GET OUTPUT HERE} -f org-mode
to work. Is this possible?
EDIT: This question has been voted to close, but the answer referenced doesn't work and wasn't tested by the user who voted to close.
echo foo | xargs -I {} emacs -nw {} -f org-mode
, or as alnx suggested,emacs -nw "$(echo foo)" -f org-mode
. – muru Jul 11 '19 at 07:05echo foo | xargs -I {} emacs -nw {} -f org-mode
returns an error for me. Does it work on your machine? – Brian Fitzpatrick Jul 11 '19 at 07:41emacs: standard input is not a tty
– Brian Fitzpatrick Jul 11 '19 at 08:02emacs
was run with the input as argument. You problem is that emacs doesn't like working in a pipeline, which means the idea behind your entire question is broken. Use a better editor – muru Jul 11 '19 at 08:08echo foo | xargs -I {} emacs -nw {} -f org-mode
and now you're saying that my question is broken. The existence of an answer and my question being "broken" are mutually exclusive. – Brian Fitzpatrick Jul 11 '19 at 08:13xargs
method there works in this aspect: the output of the command is used as an argument andemacs
is started with that argument. In as much as this is your question, the method works - you can use stdout in the middle of a command. Try, say,echo
orcat
orvim
, and you'll see the effect. The error you're getting is this: Afteremacs
has been started with that argument, it sees that the input is a pipe, and it breaks. So the problem in the question has been solved, and now you have a new problem, which breaks your overall idea. Is that clearer? – muru Jul 11 '19 at 08:31emacs
behaves differently than the other commands. Why? This is totally not obvious. – Brian Fitzpatrick Jul 11 '19 at 08:33echo foo | xargs -I{} emacs -t /dev/tty -nw {} -f org-mode
appears to work (no idea if there are other implications though) – steeldriver Jul 11 '19 at 11:10EDITOR=emacsclient....
in various ways, see the link. – meuh Jul 11 '19 at 15:26