Skip to content

Commit

Permalink
Properly detect Mac OS X using xolox#misc#os#is_mac()
Browse files Browse the repository at this point in the history
Related to vim-shell issue #18:
  xolox/vim-shell#18
  • Loading branch information
xolox committed Jun 19, 2013
1 parent b9391f4 commit aea5599
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 13 deletions.
12 changes: 10 additions & 2 deletions README.md
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion autoload/xolox/misc.vim
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion autoload/xolox/misc/open.vim
Expand Up @@ -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))
Expand Down
27 changes: 25 additions & 2 deletions autoload/xolox/misc/os.vim
@@ -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')
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions autoload/xolox/misc/path.vim
@@ -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
Expand Down
20 changes: 15 additions & 5 deletions doc/misc.txt
Expand Up @@ -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
Expand Down Expand Up @@ -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*
Expand Down Expand Up @@ -393,6 +394,15 @@ is returned.
*misc-operating-system-interfaces*
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

Expand Down

0 comments on commit aea5599

Please sign in to comment.