|
1 | 1 | " Operating system interfaces.
|
2 | 2 | "
|
3 | 3 | " Author: Peter Odding <peter@peterodding.com>
|
4 |
| -" Last Change: May 19, 2013 |
| 4 | +" Last Change: May 20, 2013 |
5 | 5 | " URL: http://peterodding.com/code/vim/misc/
|
6 | 6 |
|
7 |
| -let g:xolox#misc#os#version = '0.3' |
| 7 | +let g:xolox#misc#os#version = '0.4' |
8 | 8 |
|
9 | 9 | function! xolox#misc#os#is_win() " {{{1
|
10 | 10 | " Returns 1 (true) when on Microsoft Windows, 0 (false) otherwise.
|
11 | 11 | return has('win16') || has('win32') || has('win64')
|
12 | 12 | endfunction
|
13 | 13 |
|
| 14 | +function! xolox#misc#os#find_vim() " {{{1 |
| 15 | + " Returns the program name of Vim as a string. On Windows and UNIX this |
| 16 | + " simply returns [v:progname] [progname] while on Mac OS X there is some |
| 17 | + " special magic to find MacVim's executable even though it's usually not on |
| 18 | + " the executable search path. |
| 19 | + " |
| 20 | + " [progname]: http://vimdoc.sourceforge.net/htmldoc/eval.html#v:progname |
| 21 | + let progname = '' |
| 22 | + if has('macunix') |
| 23 | + " Special handling for Mac OS X where MacVim is usually not on the $PATH. |
| 24 | + call xolox#misc#msg#debug("os.vim %s: Trying MacVim workaround to find Vim executable ..", g:xolox#misc#os#version) |
| 25 | + let segments = xolox#misc#path#split($VIMRUNTIME) |
| 26 | + if segments[-3:] == ['Resources', 'vim', 'runtime'] |
| 27 | + let progname = xolox#misc#path#join(segments[0:-4] + ['MacOS', 'Vim']) |
| 28 | + call xolox#misc#msg#debug("os.vim %s: The MacVim workaround resulted in the Vim executable %s.", g:xolox#misc#os#version, string(progname)) |
| 29 | + endif |
| 30 | + endif |
| 31 | + if empty(progname) |
| 32 | + call xolox#misc#msg#debug("os.vim %s: Looking for Vim executable named %s on search path ..", g:xolox#misc#os#version, string(v:progname)) |
| 33 | + let candidates = xolox#misc#path#which(v:progname) |
| 34 | + if !empty(candidates) |
| 35 | + call xolox#misc#msg#debug("os.vim %s: Found %i candidate(s) on search path: %s.", g:xolox#misc#os#version, len(candidates), string(candidates)) |
| 36 | + let progname = candidates[0] |
| 37 | + endif |
| 38 | + endif |
| 39 | + call xolox#misc#msg#debug("os.vim %s: Reporting Vim executable %s.", g:xolox#misc#os#version, string(progname)) |
| 40 | + return progname |
| 41 | +endfunction |
| 42 | + |
14 | 43 | function! xolox#misc#os#exec(options) " {{{1
|
15 | 44 | " Execute an external command (hiding the console on Microsoft Windows when
|
16 | 45 | " my [vim-shell plug-in] [vim-shell] is installed).
|
@@ -63,9 +92,7 @@ function! xolox#misc#os#exec(options) " {{{1
|
63 | 92 | if !async
|
64 | 93 | let tempout = tempname()
|
65 | 94 | let temperr = tempname()
|
66 |
| - let cmd = printf('(%s) 1>%s 2>%s', cmd, |
67 |
| - \ xolox#misc#escape#shell(tempout), |
68 |
| - \ xolox#misc#escape#shell(temperr)) |
| 95 | + let cmd = printf('(%s) 1>%s 2>%s', cmd, xolox#misc#escape#shell(tempout), xolox#misc#escape#shell(temperr)) |
69 | 96 | endif
|
70 | 97 |
|
71 | 98 | " If A) we're on Windows, B) the vim-shell plug-in is installed and C) the
|
|
0 commit comments