Skip to content

Commit

Permalink
Enable passing stdin to xolox#shell#execute()
Browse files Browse the repository at this point in the history
This enables integration with my luainspect.vim plug-in.
  • Loading branch information
xolox committed Aug 10, 2010
1 parent 2f64141 commit fc16d5c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions TODO.md
@@ -1,5 +1,7 @@
* Test the `shell.dll` library on as many configurations as possible! (different Windows versions, 32 vs. 64 bit, etc.)

* Document how to pass standard input to shell commands using xolox#shell#execute().

* Replace the temporary file hack with a proper silent `popen()` implementation?

* I've [announced this plug-in](http://groups.google.com/group/vim_dev/browse_frm/thread/2cdeb5709fbfc0a0) on the vim-dev mailing list but received some criticism. So for future reference: The problem solved by `xolox#shell#execute()` really does exist, see for example the [Syntastic script page](http://www.vim.org/scripts/script.php?script_id=2736) which says: "This plugin is currently only recommended for UNIX users. It is functional on Windows, but since the syntax checking plugins shell out, the command window briefly appears whenever one is executed."
23 changes: 15 additions & 8 deletions autoload.vim
@@ -1,6 +1,6 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
" Last Change: August 9, 2010
" Last Change: August 10, 2010
" URL: http://peterodding.com/code/vim/shell/

if !exists('s:script')
Expand Down Expand Up @@ -142,12 +142,18 @@ function! xolox#shell#highlight_urls() " -- highlight URLs and e-mail addresses
endif
endfunction

function! xolox#shell#execute(command, synchronous) " -- execute external commands asynchronously {{{1
function! xolox#shell#execute(command, synchronous, ...) " -- execute external commands asynchronously {{{1
try
let cmd = a:command
let has_input = a:0 > 0
if has_input
let tempin = tempname()
call writefile(type(a:1) == type([]) ? a:1 : split(a:1, "\n"), tempin)
let cmd .= ' < ' . shellescape(tempin)
endif
if a:synchronous
let tempfile = tempname()
let cmd .= ' > ' . shellescape(tempfile) . ' 2>&1'
let tempout = tempname()
let cmd .= ' > ' . shellescape(tempout) . ' 2>&1'
endif
if s:is_windows() && s:has_dll()
let fn = 'execute_' . (a:synchronous ? '' : 'a') . 'synchronous'
Expand All @@ -165,18 +171,19 @@ function! xolox#shell#execute(command, synchronous) " -- execute external comman
call s:handle_error(cmd, output)
endif
if a:synchronous
if !filereadable(tempfile)
if !filereadable(tempout)
let msg = '%s: Failed to execute %s!'
throw printf(msg, s:script, strtrans(cmd))
endif
let output = readfile(tempfile)
call delete(tempfile)
return output
return readfile(tempout)
else
return 1
endif
catch
call xolox#warning("%s: %s at %s", s:script, v:exception, v:throwpoint)
finally
if exists('tempin') | call delete(tempin) | endif
if exists('tempout') | call delete(tempout) | endif
endtry
endfunction

Expand Down
4 changes: 2 additions & 2 deletions shell.vim
@@ -1,9 +1,9 @@
" Vim plug-in
" Author: Peter Odding <peter@peterodding.com>
" Last Change: August 9, 2010
" Last Change: August 10, 2010
" URL: http://peterodding.com/code/vim/shell/
" License: MIT
" Version: 0.7
" Version: 0.7.1

" Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3123 1 :AutoInstall: shell.zip
Expand Down

0 comments on commit fc16d5c

Please sign in to comment.