Skip to content

Commit aeaca88

Browse files
authored
Merge pull request #33 from nyarla/add-lib.os
feat(lib.os): add manupilate library for the runtime os of nvim
2 parents d22b113 + b25a5ff commit aeaca88

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

lua/lib/os.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
local M = {}
2+
3+
---@return string the os name about nvim running on
4+
function M.detect_os()
5+
if vim.fn.filereadable("/etc/NIXOS") == 1 then
6+
return "nixos"
7+
end
8+
9+
if vim.fn.executable("sw_vers") == 1 then
10+
return "macos"
11+
end
12+
13+
if vim.fn.executable("explorer.exe") == 1 then
14+
return "windows"
15+
end
16+
17+
if vim.fn.system("uname -s") == "Linux\n" then
18+
return "linux"
19+
end
20+
21+
return "unsupported"
22+
end
23+
24+
return M

spec/lib/os_spec.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local lib = require("lib.os")
2+
3+
describe("lib", function()
4+
it("os#detect_os", function()
5+
assert.are.same(lib.detect_os(), "linux")
6+
end)
7+
end)

0 commit comments

Comments
 (0)