1
Fork 0
satellite/home/features/neovim/config/lua/my/helpers/env.lua

56 lines
1 KiB
Lua
Raw Normal View History

2023-01-10 02:38:06 +01:00
local function makeEnv(cond)
return {
-- I am doing this to get type hints!
active = function()
2023-12-02 12:16:33 +01:00
return cond()
end,
2023-01-10 02:38:06 +01:00
not_active = function()
return not cond()
end,
unless = function(f)
if not cond() then
f()
end
end,
when = function(f)
if cond() then
f()
end
end,
}
end
2023-12-02 12:16:33 +01:00
local M = {
2023-01-10 02:38:06 +01:00
vscode = makeEnv(function()
return vim.g.vscode ~= nil
end),
neovide = makeEnv(function()
2023-01-22 01:22:38 +01:00
return vim.g.neovide ~= nil or require("nix.env") == "neovide"
2023-01-10 02:38:06 +01:00
end),
firenvim = makeEnv(function()
2023-03-16 22:22:06 +01:00
return vim.g.started_by_firenvim ~= nil or require("nix.env") == "firenvim"
2023-01-10 02:38:06 +01:00
end),
_and = function(a, b)
return makeEnv(function()
return a.active() and b.active()
end)
end,
_or = function(a, b)
return makeEnv(function()
return a.active() or b.active()
end)
end,
2023-01-10 02:38:06 +01:00
}
2023-12-02 12:16:33 +01:00
M.blacklist = function(list)
for _, key in pairs(list) do
if M[key].active() then
return false
end
end
return true
end
return M