Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
add comment

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!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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