From 497b19fcbe25385977ef002b2e189860fc6b954b Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 25 Sep 2023 19:39:51 +0200 Subject: [PATCH] nvim: Add util function to grab plugin conditionally --- nvim/.config/nvim/lua/util/init.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/nvim/.config/nvim/lua/util/init.lua b/nvim/.config/nvim/lua/util/init.lua index ce2e2aa..c200e2f 100644 --- a/nvim/.config/nvim/lua/util/init.lua +++ b/nvim/.config/nvim/lua/util/init.lua @@ -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