Capture the output of an interactive script in vim -
i have interactive perl script, prints prompts stderr , reads lines stdin. final output of script ip address, printed stdout. here's numpty version of such script example.
my @pieces; (1..4) { print stderr "please come in piece $_ of ip:"; chomp(my $in = <>); force @pieces, $in; } print bring together '.', @pieces; print "\n";
i utilize vim-fireplace vim plugin. plugin has feature can say:
:connect nrepl://127.0.0.1:9999
i want know how configure vim when issue particular command, let's say:
:interactiveconnect
it following:
run perl script, allowing me come in 4 pieces of ip address. capture ip address output perl script. interpolate ip address :connect command run :connect command.a bit more info based on of responses:
if phone call script using:
:!/path/to/myscript.pl
then executes fine , able see result printed in vim window, followed by
press come in or type command go on
if output of script beingness saved in buffer after execution via !, possible access buffer in vimscript , capture bit want (the lastly line) regex?
okay, there's more elegant way this, how this:
function! <sid>interactiveconnect() allow tempfile=tempname() exe '!/path/to/your/script.pl >' . shellescape(tempfile) seek exe 'connect nrepl://' . readfile(tempfile, '', -1)[0] phone call delete(tempfile) endtry endfunction command! -nargs=0 interactiveconnect phone call <sid>interactiveconnect()
this creates temporary file, writes script (using system()
doesn't work because doesn't wait input), reads lastly line in tempfile connect
command, , deletes tempfile.
vim
No comments:
Post a Comment