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
1 changed files with 10 additions and 2 deletions

View File

@ -5,10 +5,18 @@ local T = {}
---@param plugin string The plugin to search for
---@return boolean available # Whether the plugin is available
function T.is_available(plugin)
local lazy_config_avail, lazy_config = pcall(require, "lazy.core.config")
return lazy_config_avail and lazy_config.plugins[plugin] ~= nil
return T.get_plugin(plugin) and true or false
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)
return require("util.pyenv").get_path(workspace)
end