Skip to content

Commit aea5599

Browse files
committed
Properly detect Mac OS X using xolox#misc#os#is_mac()
Related to vim-shell issue #18: xolox/vim-shell#18
1 parent b9391f4 commit aea5599

File tree

6 files changed

+54
-13
lines changed

6 files changed

+54
-13
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ from the source code of the miscellaneous scripts using the Python module
3737

3838
<!-- Start of generated documentation -->
3939

40-
The documentation of the 67 functions below was extracted from
41-
15 Vim scripts on June 19, 2013 at 21:00.
40+
The documentation of the 68 functions below was extracted from
41+
15 Vim scripts on June 19, 2013 at 21:05.
4242

4343
### Handling of special buffers
4444

@@ -280,6 +280,14 @@ otherwise (so by default) a list with all matches is returned.
280280

281281
### Operating system interfaces
282282

283+
#### The `xolox#misc#os#is_mac()` function
284+
285+
Returns 1 (true) when on Mac OS X, 0 (false) otherwise. You would expect
286+
this to simply check the Vim feature list, but for some obscure reason the
287+
`/usr/bin/vim` included in Mac OS X (verified on version 10.7.5) returns 0
288+
(false) in response to `has('mac')`, so we check the output of `uname`
289+
to avoid false negatives.
290+
283291
#### The `xolox#misc#os#is_win()` function
284292

285293
Returns 1 (true) when on Microsoft Windows, 0 (false) otherwise.

autoload/xolox/misc.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
" Last Change: June 19, 2013
55
" URL: http://peterodding.com/code/vim/misc/
66

7-
let g:xolox#misc#version = '1.6.1'
7+
let g:xolox#misc#version = '1.6.2'

autoload/xolox/misc/open.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function! xolox#misc#open#file(location, ...) " {{{1
2929
silent execute printf(command, xolox#misc#escape#shell(a:location))
3030
endtry
3131
return
32-
elseif has('macunix')
32+
elseif xolox#misc#os#is_mac()
3333
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))
3434
let cmd = 'open ' . shellescape(a:location) . ' 2>&1'
3535
call s:handle_error(cmd, system(cmd))

autoload/xolox/misc/os.vim

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
11
" Operating system interfaces.
22
"
33
" Author: Peter Odding <[email protected]>
4-
" Last Change: June 3, 2013
4+
" Last Change: June 19, 2013
55
" URL: http://peterodding.com/code/vim/misc/
66

7+
function! xolox#misc#os#is_mac() " {{{1
8+
" Returns 1 (true) when on Mac OS X, 0 (false) otherwise. You would expect
9+
" this to simply check the Vim feature list, but for some obscure reason the
10+
" `/usr/bin/vim` included in Mac OS X (verified on version 10.7.5) returns 0
11+
" (false) in response to `has('mac')`, so we check the output of `uname`
12+
" to avoid false negatives.
13+
if !exists('s:is_mac')
14+
" By default we assume we are *not* on Mac OS X.
15+
let s:is_mac = 0
16+
if has('mac') || has('macunix') || has('gui_mac')
17+
" If Vim's feature list indicates we are on Mac OS X, we have our answer :-).
18+
let s:is_mac = 1
19+
else
20+
" Otherwise we check the output of `uname' to avoid false negatives.
21+
let result = xolox#misc#os#exec({'command': 'uname', 'check': 0})
22+
if result['exit_code'] == 0 && get(result['stdout'], 0, '') == 'Darwin'
23+
let s:is_mac = 1
24+
endif
25+
endif
26+
endif
27+
return s:is_mac
28+
endfunction
29+
730
function! xolox#misc#os#is_win() " {{{1
831
" Returns 1 (true) when on Microsoft Windows, 0 (false) otherwise.
932
return has('win16') || has('win32') || has('win64')
@@ -32,7 +55,7 @@ function! xolox#misc#os#find_vim(...) " {{{1
3255
else
3356
let pathname = ''
3457
endif
35-
if empty(pathname) && has('macunix')
58+
if empty(pathname) && xolox#misc#os#is_mac()
3659
" Special handling for Mac OS X where MacVim is usually not on the $PATH.
3760
" This always returns the "Vim" executable and not "MacVim" (regardless of
3861
" the caller's preference) because "MacVim" has funky dock magic going on.

autoload/xolox/misc/path.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
" Pathname manipulation functions.
22
"
33
" Author: Peter Odding <[email protected]>
4-
" Last Change: June 2, 2013
4+
" Last Change: June 19, 2013
55
" URL: http://peterodding.com/code/vim/misc/
66

77
let s:windows_compatible = xolox#misc#os#is_win()
8-
let s:mac_os_x_compatible = has('macunix')
8+
let s:mac_os_x_compatible = xolox#misc#os#is_mac()
99

1010
function! xolox#misc#path#which(...) " {{{1
1111
" Scan the executable search path (`$PATH`) for one or more external

doc/misc.txt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ Contents ~
3838
5. The |xolox#misc#option#join_tags()| function
3939
6. The |xolox#misc#option#eval_tags()| function
4040
9. Operating system interfaces |misc-operating-system-interfaces|
41-
1. The |xolox#misc#os#is_win()| function
42-
2. The |xolox#misc#os#find_vim()| function
43-
3. The |xolox#misc#os#exec()| function
41+
1. The |xolox#misc#os#is_mac()| function
42+
2. The |xolox#misc#os#is_win()| function
43+
3. The |xolox#misc#os#find_vim()| function
44+
4. The |xolox#misc#os#exec()| function
4445
10. Pathname manipulation functions |misc-pathname-manipulation-functions|
4546
1. The |xolox#misc#path#which()| function
4647
2. The |xolox#misc#path#split()| function
@@ -136,8 +137,8 @@ For those who are curious: The function descriptions given below were extracted
136137
from the source code of the miscellaneous scripts using the Python module
137138
'vimdoctool.py' included in vim-tools [5].
138139

139-
The documentation of the 67 functions below was extracted from 15 Vim scripts
140-
on June 19, 2013 at 21:00.
140+
The documentation of the 68 functions below was extracted from 15 Vim scripts
141+
on June 19, 2013 at 21:05.
141142

142143
-------------------------------------------------------------------------------
143144
*misc-handling-of-special-buffers*
@@ -393,6 +394,15 @@ is returned.
393394
*misc-operating-system-interfaces*
394395
Operating system interfaces ~
395396

397+
-------------------------------------------------------------------------------
398+
The *xolox#misc#os#is_mac()* function
399+
400+
Returns 1 (true) when on Mac OS X, 0 (false) otherwise. You would expect this
401+
to simply check the Vim feature list, but for some obscure reason the
402+
'/usr/bin/vim' included in Mac OS X (verified on version 10.7.5) returns 0
403+
(false) in response to "has('mac')", so we check the output of 'uname' to avoid
404+
false negatives.
405+
396406
-------------------------------------------------------------------------------
397407
The *xolox#misc#os#is_win()* function
398408

0 commit comments

Comments
 (0)