Skip to content

Commit 9b4c774

Browse files
committed
xolox#misc#os#exec() uses xolox#shell#execute() when available, falls back to system()
1 parent d7b3e0c commit 9b4c774

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

os.vim

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: March 15, 2011
3+
" Last Change: November 24, 2011
44
" URL: http://peterodding.com/code/vim/misc/
55

6+
let g:xolox#misc#os#version = '0.1'
7+
68
" Check whether Vim is running on Microsoft Windows.
79

810
function! xolox#misc#os#is_win()
911
return has('win16') || has('win32') || has('win64')
1012
endfunction
1113

14+
" Execute an external command (hiding the console on Windows when possible).
15+
16+
function! xolox#misc#os#exec(cmdline, ...)
17+
try
18+
" Try using my shell.vim plug-in.
19+
return call('xolox#shell#execute', [a:cmdline, 1] + a:000)
20+
catch /^Vim\%((\a\+)\)\=:E117/
21+
" Fall back to system() when we get an "unknown function" error.
22+
let output = call('system', [a:cmdline] + a:000)
23+
if v:shell_error
24+
throw printf("os.vim %s: Command %s failed: %s", g:xolox#misc#os#version, a:cmdline, xolox#misc#str#trim(output))
25+
endif
26+
return split(output, "\n")
27+
endtry
28+
endfunction
29+
1230
" vim: ts=2 sw=2 et

0 commit comments

Comments
 (0)