Keeping bash open on a named pipe

3

2

I'm looking to send commands to a separate tmux pane from vim and I figured the easiest way was to mkfifo a named pipe /tmp/cmds and run bash < /tmp/cmds to listen for commands to run.

I then do echo "echo \"hello world\" > /tmp/cmds" as test, this only works for one command and xargs closes immediately. Is there any way to keep this running after more than one command?

William Casarin

Posted 2012-08-09T16:21:56.117

Reputation: 720

Answers

1

this is no different from running xargs on the interactive shell and terminate with a newline, so it will finish and exit.

you would have to write a loop and execute for each line of input from stdin such as

while :; do xargs < /tmp/cmds; done

not tested so you may need to tweak.

johnshen64

Posted 2012-08-09T16:21:56.117

Reputation: 4 399

0

If anyone was wondering, here's the script I use for sending commands from vim:

#!/bin/sh
FIFO=${1:-"/tmp/cmds"}
mkfifo $FIFO &> /dev/null
while :; do bash < $FIFO && echo "== OK ==" || echo "!! ERR !!"; done

Here's a vim function to send commands to this pipe:

function! RCmd(cmd)
  :silent! exe '!echo "cd ' . getcwd() . ' && ' . a:cmd . '" > /tmp/cmds'
  :redraw!
endfunction

A mapping that sends make to the window on <F4>

map <F4> :call RCmd("make")<CR>

Have fun!

William Casarin

Posted 2012-08-09T16:21:56.117

Reputation: 720