diff --git a/README.md b/README.md index 8d6c916..db7526a 100644 --- a/README.md +++ b/README.md @@ -42,8 +42,7 @@ return { When plugins don't conform to the unofficial standard outlined above, then a placeholder config is generated, for example, `$HOME/.config/nvim/lua/plugins/grapple.lua`: ```lua --- No example configuration was found for this plugin. --- +-- No example configuration was found for this plugin, a default has been configured. -- For detailed information on configuring this plugin, please refer to its -- official documentation: -- @@ -53,7 +52,8 @@ When plugins don't conform to the unofficial standard outlined above, then a pla -- the configuration below. return { - -- "cbochs/grapple.nvim" + "cbochs/grapple.nvim", + opts = {} } ``` @@ -76,3 +76,11 @@ return { } } ``` + +## Configuration + +```lua +{ + open_config_after_creation = true +} +``` diff --git a/lua/activate/config.lua b/lua/activate/config.lua new file mode 100644 index 0000000..3c1688e --- /dev/null +++ b/lua/activate/config.lua @@ -0,0 +1,15 @@ +local M = {} + +---@class Activate.Config +M.config = {} + +---@class Activate.Config +local defaults = { + open_config_after_creation = true, +} + +M.setup = function(user_config) + M.config = vim.tbl_deep_extend("force", defaults, user_config or {}) +end + +return M diff --git a/lua/activate/init.lua b/lua/activate/init.lua index f70b64f..f50de16 100644 --- a/lua/activate/init.lua +++ b/lua/activate/init.lua @@ -113,6 +113,8 @@ local function create_picker(title, prompt, items, mappings_func) plugin_picker:find() end +M.setup = require("activate.config").setup + M.list_plugins = function() local items = utils.get_all_plugins() create_picker( diff --git a/lua/activate/types.lua b/lua/activate/types.lua new file mode 100644 index 0000000..e742ee4 --- /dev/null +++ b/lua/activate/types.lua @@ -0,0 +1,2 @@ +---@class Activate.Config +---@field open_config_after_creation boolean Should the newly created configuration open after it is created, default: `true` diff --git a/lua/activate/utils.lua b/lua/activate/utils.lua index 4adc564..f77e5ac 100644 --- a/lua/activate/utils.lua +++ b/lua/activate/utils.lua @@ -1,3 +1,4 @@ +---@module "activate.types" local M = {} local api = vim.api @@ -132,8 +133,7 @@ M.create_plugin_file = function(plugin_name, repo, _config, edit) f:write(config) else local disclaimer = [[ - -- No example configuration was found for this plugin. - -- + -- No example configuration was found for this plugin, a default has been configured. -- For detailed information on configuring this plugin, please refer to its -- official documentation: -- @@ -148,7 +148,8 @@ M.create_plugin_file = function(plugin_name, repo, _config, edit) f:write(disclaimer) f:write("\n") f:write("return {\n") - f:write(string.format(' -- "%s"\n', repo)) + f:write(string.format(' "%s",\n', repo)) + f:write(' opts = {}\n') f:write("}") end f:close() @@ -326,6 +327,8 @@ local function help() end M.all_plugins_mappings = function(prompt_bufnr, map) + ---@class Activate.Config + local user_conf = require("activate.config").config local action_state = require("telescope.actions.state") local function install_and_or_configure_plugin() @@ -333,7 +336,7 @@ M.all_plugins_mappings = function(prompt_bufnr, map) vim.api.nvim_buf_delete(prompt_bufnr, { force = true }) M._install_plugin(entry) local repo_path = entry.url:gsub("https://github.com/", "") - local edit = true + local edit = user_conf.open_config_after_creation M.create_plugin_file(entry.plugin_name, repo_path, entry.config, edit) end