2017-02-15 23:49:16 +08:00
|
|
|
---
|
2020-09-14 22:47:49 +08:00
|
|
|
title: "system API"
|
2018-09-25 22:09:28 +08:00
|
|
|
description: "system API provides some basic functions and values for current os."
|
2017-02-15 23:49:16 +08:00
|
|
|
---
|
|
|
|
|
2018-06-03 10:40:11 +08:00
|
|
|
# [Available APIs](../) >> system
|
2017-02-17 21:02:14 +08:00
|
|
|
|
2021-08-14 09:30:57 +08:00
|
|
|
<!-- vim-markdown-toc GFM -->
|
|
|
|
|
|
|
|
- [Intro](#intro)
|
|
|
|
- [Valuables](#valuables)
|
|
|
|
- [Functions](#functions)
|
|
|
|
- [Usage](#usage)
|
|
|
|
|
|
|
|
<!-- vim-markdown-toc -->
|
|
|
|
|
|
|
|
## Intro
|
|
|
|
|
|
|
|
The `system` provides basic functions for os detection.
|
|
|
|
|
|
|
|
## Valuables
|
2017-02-15 23:49:16 +08:00
|
|
|
|
2018-06-03 10:40:11 +08:00
|
|
|
| name | values | description |
|
|
|
|
| --------- | :----: | -------------------------- |
|
|
|
|
| isWindows | 0 or 1 | check if the os is windows |
|
|
|
|
| isLinux | 0 or 1 | check if the os is linux |
|
|
|
|
| isOSX | 0 or 1 | check if the os is OSX |
|
2017-02-16 23:14:23 +08:00
|
|
|
|
2021-08-14 09:30:57 +08:00
|
|
|
## Functions
|
|
|
|
|
|
|
|
| name | description |
|
|
|
|
| ------------ | ---------------------------------------- |
|
|
|
|
| fileformat() | return the icon of current file format |
|
|
|
|
| isDarwin() | return 0 or 1, check if the os is Darwin |
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
This api can be used in both vim script and lua script.
|
|
|
|
|
|
|
|
**vim script:**
|
|
|
|
|
|
|
|
```vim
|
|
|
|
let s:system = SpaceVim#api#import('system')
|
|
|
|
|
|
|
|
" check the if current os is Windows.
|
|
|
|
if s:system.isWindows
|
|
|
|
echom "OS is Windows"
|
|
|
|
endif
|
|
|
|
```
|
|
|
|
|
|
|
|
**lua script:**
|
|
|
|
|
|
|
|
```lua
|
|
|
|
local sys = require('spacevim.api').import('system')
|
2018-06-03 10:40:11 +08:00
|
|
|
|
2021-08-14 09:30:57 +08:00
|
|
|
if sys.isWindows == 1 then
|
|
|
|
print('this is windows os!')
|
|
|
|
end
|
|
|
|
```
|