Spawn a terminal and redirect its stdout to original process
1
vote
2
answers
1491
views
I'm trying to spawn a new terminal, execute a few commands and pipe their output to stdin of the original process. A mwe of what I'm trying to do is the following bash one-liner:
$ xterm -e sh -c "echo -e 'foo\nbar' > /proc/$$/fd/1" | grep foo
where I spawn a new xterm window, print foo\nbar
and try to redirect it to stdin of the shell I'm executing this command from. To see if it works I then pipe it into grep
.
The code above prints both foo
and bar
to stdout instead of just foo
, but I'm not sure why. How can I fix this?
EDIT: the real case implementation of this is a file picker that uses fzf:
#!/usr/bin/env bash
function open() {
# takes a bunch of file names (either passed as arguments or from stdin) and
# opens them
true
}
# This is what I have now
alacritty \
-e sh -c 'fzf -m --prompt="Open> " --border=horizontal --print0 \
| (nohup xargs -0 bash -c '\''open "$@"'\'' _ &>/dev/null &)'
# This is what I'm trying to do
# alacritty \
# -e sh -c "fzf -m --prompt='Open> ' --border=horizontal > /proc/$$/fd/1" \
# | open
Asked by noibe
(407 rep)
Mar 30, 2021, 10:15 PM
Last activity: May 8, 2022, 03:08 PM
Last activity: May 8, 2022, 03:08 PM