Source code to eet (license is GPL3)
Compile with
gcc -o eet eet.c
At some point I wrote a program that allows me to splice in data from other sources into a terminal process. This program is essentially the reverse of tee (which splits one input stream into an output stream and saves it to a file at the same time)
eet takes input from the terminal and from a named pipe (FIFO) thus making it as though anything that is sent to the named pipe was written directly on the terminal.
I use the following aliases to start up matlab or R with output coming from the terminal or from a named pipe.
alias oo="eet ${HOME}/.matlabFifo octave --interactive"
alias mm="eet ${HOME}/.matlabFifo matlab -nodesktop -nosplash"
alias rr="eet ${HOME}/.rFifo R --no-save"
alias rd="eet ${HOME}/.rFifo R -d gdb --no-save"
I have a bunch of VIM macros that then send lines that I'm editing to the named pipe. So basically I can open an interpreter under eet and both type commands in the interpreter and send them directly from a file. This works very well.
The VIM macro is:
noremap <silent> <CR> :exec '.!tee '.interpreterFifo<CR>j
" noremap <CR> :exec '.!tee '.interpreterFifo<CR>j
noremap <silent> <C-T> :call SendToFifo(@0,interpreterFifo)<CR>
" control / wouldn't map correctly
noremap ^_ :call ToggleEnterSendsToFifo()<CR>
noremap <silent> <C-N> :call InterruptInterpreter(interpreterFifo)<CR>
function InterruptInterpreter(interpreterFifo)
if a:interpreterFifo != "/home/mgeorg/defaultFifo"
" let pidFileName = a:interpreterFifo
" let pidFileName = substitute(pidFileName,"Fifo","Pid","")
" silent exec '!kill -SIGINT `cat '.pidFileName.'`'
silent exec '!kill -SIGINT `cat '.a:interpreterFifo.'.pid`'
" echo "!kill -SIGINT `cat ".pidFileName."`"
endif
endfunction
function SendToFifo(string,interpreterFifo)
" yank z
" " let command = strtrans(@z)
" let command = getline(".")
" let command = @0
if a:interpreterFifo != "/home/mgeorg/defaultFifo"
let command = a:string
let command = substitute(command,"\\","\\\\\\\\","g")
let command = substitute(command,"'","'\\\\''","g")
let command = substitute(command,"%","\\\\%","g")
let command = substitute(command,"#","\\\\#","g")
let command = substitute(command,"!","\\\\!","g")
" note, everything becomes Carriage Return.
" Perhaps I should look for \r\n first?
" ... I'll deal with compatibility when it bites me.
let command = substitute(command,nr2char(10),"\\\\n","g")
let command = substitute(command,nr2char(13),"\\\\n","g")
let command = "!echo -ne '".command."' > ".a:interpreterFifo
silent execute command
" echo command
" let g:gcommand = command
endif
endfunction
function ToggleEnterSendsToFifo()
if !exists("g:mappedEnter") || g:mappedEnter == 0
let g:mappedEnter = 1
inoremap <CR> <CR><ESC>kyy:call SendToFifo(@0,interpreterFifo)<CR>j^i
else
let g:mappedEnter = 0
iunmap <CR>
endif
endfunction
I obviously polished this code a lot (yeah right), so your milage may vary.