nvim: Add util function to grab plugin conditionally

This commit is contained in:
Marty Oehme 2023-09-25 19:39:51 +02:00
parent 41934d3000
commit 497b19fcbe
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -5,10 +5,18 @@ local T = {}
---@param plugin string The plugin to search for ---@param plugin string The plugin to search for
---@return boolean available # Whether the plugin is available ---@return boolean available # Whether the plugin is available
function T.is_available(plugin) function T.is_available(plugin)
local lazy_config_avail, lazy_config = pcall(require, "lazy.core.config") return T.get_plugin(plugin) and true or false
return lazy_config_avail and lazy_config.plugins[plugin] ~= nil
end end
-- Get the plugin file handle if it exists, return nil otherwise
function T.get_plugin(plugin)
local status, lib = pcall(require, plugin)
if(status) then return lib end
return nil
end
-- get the current python environment
-- return its path
function T.get_python_venv(workspace) function T.get_python_venv(workspace)
return require("util.pyenv").get_path(workspace) return require("util.pyenv").get_path(workspace)
end end