Skip to content

Commit f9eba7d

Browse files
committed
Add Detect If You Are On A Mac as a vim til
1 parent 3eeb5f1 commit f9eba7d

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
1010
For a steady stream of TILs from a variety of rocketeers, checkout
1111
[til.hashrocket.com](https://til.hashrocket.com/).
1212

13-
_548 TILs and counting..._
13+
_549 TILs and counting..._
1414

1515
---
1616

@@ -561,6 +561,7 @@ _548 TILs and counting..._
561561
- [Delete To The End Of The Line](vim/delete-to-the-end-of-the-line.md)
562562
- [Deleting Buffers In BufExplorer](vim/deleting-buffers-in-bufexplorer.md)
563563
- [Deleting Directories Of Files From netrw](vim/deleting-directories-of-files-from-netrw.md)
564+
- [Detect If You Are On A Mac](vim/detect-if-you-are-on-a-mac.md)
564565
- [Difference Between :wq and :x](vim/difference-between-wq-and-x.md)
565566
- [Display Word Count Stats](vim/display-word-count-stats.md)
566567
- [Edges Of The Selection](vim/edges-of-the-selection.md)

vim/detect-if-you-are-on-a-mac.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Detect If You Are On A Mac
2+
3+
There are a couple ways of detecting with vimscript if you are on a mac.
4+
This can be useful if you are writing a plugin with OS-specific
5+
functionality. Here are two ways to make that check.
6+
7+
```vimscript
8+
if has('macunix') || has('mac') || has('osx')
9+
...
10+
endif
11+
```
12+
13+
Alternatively, you can use Vim's `system()` function to execute unix's
14+
`uname` command. This command will give you the name of the operating
15+
system. In the event you are using a Mac, the result of `uname` should be
16+
`Darwin`. The following regex match is a good way to make this check.
17+
18+
```vimscript
19+
if system('uname') =~ "Darwin"
20+
...
21+
endif
22+
```
23+
24+
See `:h has()`, `:h system()`, and `man uname` for more details.

0 commit comments

Comments
 (0)