4

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?

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.

0
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!

1
  • I am trying to do almost similar thing. This method works well. However, I'm wondering if it is possible to do this in a way that keeps the terminal available for interactive use as well? For example: a bash session that works like a normal interactive terminal and also executes commands when something is sent to the fifo. – Punit Soni Jun 1 at 1:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.