Related to this post, Detect OS in Vimscript
This configuration detects and sets the operating system in Vim. It uses conditional statements to determine if the OS is Windows or Unix-like.
if !exists("g:os")
if has("win64") || has("win32") || has("win16")
let g:os = "Windows"
else
let g:os = substitute(system('uname'), '\n', '', '')
endif
endif
Is there a more efficient or elegant way to achieve this in Lua?
PS: I'm a newbie at this. This is my first try. Please let me know if it needs any fix.
if not vim.g.os then
local is_windows = vim.fn.has("win64") or vim.fn.has("win32") or vim.fn.has("win16")
if is_windows then
vim.g.os = "Windows"
else
local uname_output = vim.fn.system('uname')
vim.g.os = string.gsub(uname_output, '\n', '')
end
end
There's a bug. This code shows Windows
in my fedora
system.
lua
solution at How can I determine the OS of the system from within a Lua script?. I use the trick of @AgentRev in myinit.lua
.