Permalink
Browse files

Properly detect Mac OS X using xolox#misc#os#is_mac()

Related to vim-shell issue #18:
  xolox/vim-shell#18
  • Loading branch information...
1 parent b9391f4 commit aea5599d8783446c364c3969b32820b1bef94c1f @xolox committed Jun 19, 2013
Showing with 54 additions and 13 deletions.
  1. +10 −2 README.md
  2. +1 −1 autoload/xolox/misc.vim
  3. +1 −1 autoload/xolox/misc/open.vim
  4. +25 −2 autoload/xolox/misc/os.vim
  5. +2 −2 autoload/xolox/misc/path.vim
  6. +15 −5 doc/misc.txt
View
@@ -37,8 +37,8 @@ from the source code of the miscellaneous scripts using the Python module
<!-- Start of generated documentation -->
-The documentation of the 67 functions below was extracted from
-15 Vim scripts on June 19, 2013 at 21:00.
+The documentation of the 68 functions below was extracted from
+15 Vim scripts on June 19, 2013 at 21:05.
### Handling of special buffers
@@ -280,6 +280,14 @@ otherwise (so by default) a list with all matches is returned.
### Operating system interfaces
+#### The `xolox#misc#os#is_mac()` function
+
+Returns 1 (true) when on Mac OS X, 0 (false) otherwise. You would expect
+this to simply check the Vim feature list, but for some obscure reason the
+`/usr/bin/vim` included in Mac OS X (verified on version 10.7.5) returns 0
+(false) in response to `has('mac')`, so we check the output of `uname`
+to avoid false negatives.
+
#### The `xolox#misc#os#is_win()` function
Returns 1 (true) when on Microsoft Windows, 0 (false) otherwise.
View
@@ -4,4 +4,4 @@
" Last Change: June 19, 2013
" URL: http://peterodding.com/code/vim/misc/
-let g:xolox#misc#version = '1.6.1'
+let g:xolox#misc#version = '1.6.2'
@@ -29,7 +29,7 @@ function! xolox#misc#open#file(location, ...) " {{{1
silent execute printf(command, xolox#misc#escape#shell(a:location))
endtry
return
- elseif has('macunix')
+ elseif xolox#misc#os#is_mac()
call xolox#misc#msg#debug("vim-misc %s: Detected Mac OS X, using 'open' command to open %s ..", g:xolox#misc#version, string(a:location))
let cmd = 'open ' . shellescape(a:location) . ' 2>&1'
call s:handle_error(cmd, system(cmd))
View
@@ -1,9 +1,32 @@
" Operating system interfaces.
"
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: June 3, 2013
+" Last Change: June 19, 2013
" URL: http://peterodding.com/code/vim/misc/
+function! xolox#misc#os#is_mac() " {{{1
+ " Returns 1 (true) when on Mac OS X, 0 (false) otherwise. You would expect
+ " this to simply check the Vim feature list, but for some obscure reason the
+ " `/usr/bin/vim` included in Mac OS X (verified on version 10.7.5) returns 0
+ " (false) in response to `has('mac')`, so we check the output of `uname`
+ " to avoid false negatives.
+ if !exists('s:is_mac')
+ " By default we assume we are *not* on Mac OS X.
+ let s:is_mac = 0
+ if has('mac') || has('macunix') || has('gui_mac')
+ " If Vim's feature list indicates we are on Mac OS X, we have our answer :-).
+ let s:is_mac = 1
+ else
+ " Otherwise we check the output of `uname' to avoid false negatives.
+ let result = xolox#misc#os#exec({'command': 'uname', 'check': 0})
+ if result['exit_code'] == 0 && get(result['stdout'], 0, '') == 'Darwin'
+ let s:is_mac = 1
+ endif
+ endif
+ endif
+ return s:is_mac
+endfunction
+
function! xolox#misc#os#is_win() " {{{1
" Returns 1 (true) when on Microsoft Windows, 0 (false) otherwise.
return has('win16') || has('win32') || has('win64')
@@ -32,7 +55,7 @@ function! xolox#misc#os#find_vim(...) " {{{1
else
let pathname = ''
endif
- if empty(pathname) && has('macunix')
+ if empty(pathname) && xolox#misc#os#is_mac()
" Special handling for Mac OS X where MacVim is usually not on the $PATH.
" This always returns the "Vim" executable and not "MacVim" (regardless of
" the caller's preference) because "MacVim" has funky dock magic going on.
@@ -1,11 +1,11 @@
" Pathname manipulation functions.
"
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: June 2, 2013
+" Last Change: June 19, 2013
" URL: http://peterodding.com/code/vim/misc/
let s:windows_compatible = xolox#misc#os#is_win()
-let s:mac_os_x_compatible = has('macunix')
+let s:mac_os_x_compatible = xolox#misc#os#is_mac()
function! xolox#misc#path#which(...) " {{{1
" Scan the executable search path (`$PATH`) for one or more external
View
@@ -38,9 +38,10 @@ Contents ~
5. The |xolox#misc#option#join_tags()| function
6. The |xolox#misc#option#eval_tags()| function
9. Operating system interfaces |misc-operating-system-interfaces|
- 1. The |xolox#misc#os#is_win()| function
- 2. The |xolox#misc#os#find_vim()| function
- 3. The |xolox#misc#os#exec()| function
+ 1. The |xolox#misc#os#is_mac()| function
+ 2. The |xolox#misc#os#is_win()| function
+ 3. The |xolox#misc#os#find_vim()| function
+ 4. The |xolox#misc#os#exec()| function
10. Pathname manipulation functions |misc-pathname-manipulation-functions|
1. The |xolox#misc#path#which()| function
2. The |xolox#misc#path#split()| function
@@ -136,8 +137,8 @@ For those who are curious: The function descriptions given below were extracted
from the source code of the miscellaneous scripts using the Python module
'vimdoctool.py' included in vim-tools [5].
-The documentation of the 67 functions below was extracted from 15 Vim scripts
-on June 19, 2013 at 21:00.
+The documentation of the 68 functions below was extracted from 15 Vim scripts
+on June 19, 2013 at 21:05.
-------------------------------------------------------------------------------
*misc-handling-of-special-buffers*
@@ -394,6 +395,15 @@ is returned.
Operating system interfaces ~
-------------------------------------------------------------------------------
+The *xolox#misc#os#is_mac()* function
+
+Returns 1 (true) when on Mac OS X, 0 (false) otherwise. You would expect this
+to simply check the Vim feature list, but for some obscure reason the
+'/usr/bin/vim' included in Mac OS X (verified on version 10.7.5) returns 0
+(false) in response to "has('mac')", so we check the output of 'uname' to avoid
+false negatives.
+
+-------------------------------------------------------------------------------
The *xolox#misc#os#is_win()* function
Returns 1 (true) when on Microsoft Windows, 0 (false) otherwise.

0 comments on commit aea5599

Please sign in to comment.