mirror of
https://github.com/jdhao/nvim-config.git
synced 2025-06-08 14:14:33 +02:00
move version check into function
This commit is contained in:
parent
a602d98819
commit
659f410b9e
22
init.lua
22
init.lua
@ -11,26 +11,10 @@
|
|||||||
-- StackOverflow: https://stackoverflow.com/users/6064933/jdhao
|
-- StackOverflow: https://stackoverflow.com/users/6064933/jdhao
|
||||||
vim.loader.enable()
|
vim.loader.enable()
|
||||||
|
|
||||||
local version = vim.version
|
local utils = require("utils")
|
||||||
|
|
||||||
-- check if we have the latest stable version of nvim
|
local expected_version = "0.10.1"
|
||||||
local expected_ver_str = "0.10.1"
|
utils.is_compatible_version(expected_version)
|
||||||
local expect_ver = version.parse(expected_ver_str)
|
|
||||||
local actual_ver = vim.version()
|
|
||||||
|
|
||||||
if expect_ver == nil then
|
|
||||||
local msg = string.format("Unsupported version string: %s", expected_ver_str)
|
|
||||||
vim.api.nvim_err_writeln(msg)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local result = version.cmp(expect_ver, actual_ver)
|
|
||||||
|
|
||||||
if result ~= 0 then
|
|
||||||
local _ver = string.format("%s.%s.%s", actual_ver.major, actual_ver.minor, actual_ver.patch)
|
|
||||||
local msg = string.format("Expect nvim %s, but got %s instead. Use at your own risk!", expected_ver_str, _ver)
|
|
||||||
vim.api.nvim_err_writeln(msg)
|
|
||||||
end
|
|
||||||
|
|
||||||
local core_conf_files = {
|
local core_conf_files = {
|
||||||
"globals.lua", -- some global settings
|
"globals.lua", -- some global settings
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
local fn = vim.fn
|
local fn = vim.fn
|
||||||
|
local version = vim.version
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
@ -50,4 +51,32 @@ function M.rand_element(seq)
|
|||||||
return seq[idx]
|
return seq[idx]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- check if the current nvim version is compatible with the allowed version
|
||||||
|
--- @param expected_version string
|
||||||
|
--- @return boolean
|
||||||
|
function M.is_compatible_version(expected_version)
|
||||||
|
-- check if we have the latest stable version of nvim
|
||||||
|
local expect_ver = version.parse(expected_version)
|
||||||
|
local actual_ver = vim.version()
|
||||||
|
|
||||||
|
if expect_ver == nil then
|
||||||
|
local msg = string.format("Unsupported version string: %s", expected_version)
|
||||||
|
vim.api.nvim_err_writeln(msg)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local result = version.cmp(expect_ver, actual_ver)
|
||||||
|
if result ~= 0 then
|
||||||
|
local _ver = string.format("%s.%s.%s", actual_ver.major, actual_ver.minor, actual_ver.patch)
|
||||||
|
local msg = string.format(
|
||||||
|
"Expect nvim version %s, but your current nvim version is %s. Use at your own risk!",
|
||||||
|
expected_version,
|
||||||
|
_ver
|
||||||
|
)
|
||||||
|
vim.api.nvim_err_writeln(msg)
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user