From 8db6c5176242c2049d57bb9b30d1faac7c0cc2b1 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Sat, 11 Jan 2025 11:09:20 +0100 Subject: [PATCH] plugins/lir: init --- plugins/by-name/lir/default.nix | 35 +++++ plugins/by-name/lir/settings-options.nix | 123 ++++++++++++++++++ .../plugins/by-name/lir/default.nix | 49 +++++++ 3 files changed, 207 insertions(+) create mode 100644 plugins/by-name/lir/default.nix create mode 100644 plugins/by-name/lir/settings-options.nix create mode 100644 tests/test-sources/plugins/by-name/lir/default.nix diff --git a/plugins/by-name/lir/default.nix b/plugins/by-name/lir/default.nix new file mode 100644 index 00000000..7fa22158 --- /dev/null +++ b/plugins/by-name/lir/default.nix @@ -0,0 +1,35 @@ +{ lib, config, ... }: +lib.nixvim.plugins.mkNeovimPlugin { + name = "lir"; + packPathName = "lir.nvim"; + package = "lir-nvim"; + + maintainers = [ lib.maintainers.GaetanLepage ]; + + settingsExample = { + show_hidden_files = true; + devicons.enable = false; + mappings = { + "".__raw = "require('lir').actions.edit"; + "-".__raw = "require('lir').actions.up"; + "".__raw = "require('lir').actions.quit"; + "@".__raw = "require('lir').actions.cd"; + }; + hide_cursor = true; + }; + + extraConfig = cfg: { + warnings = + lib.optional + ( + (cfg.settings ? devicons.enable) + && (lib.isBool cfg.settings.devicons.enable) + && cfg.settings.devicons.enable + && (!config.plugins.web-devicons.enable) + ) + '' + Nixvim (plugins.lir): You have enabled `settings.devicons.enable` but `plugins.web-devicons.enable` is `false`. + Consider enabling the plugin for proper devicons support. + ''; + }; +} diff --git a/plugins/by-name/lir/settings-options.nix b/plugins/by-name/lir/settings-options.nix new file mode 100644 index 00000000..b02fe901 --- /dev/null +++ b/plugins/by-name/lir/settings-options.nix @@ -0,0 +1,123 @@ +lib: +let + inherit (lib) types; + inherit (lib.nixvim) defaultNullOpts; +in +{ + show_hidden_files = defaultNullOpts.mkBool false '' + Whether to show files whose file names start with `.` by default. + ''; + + ignore = defaultNullOpts.mkListOf' { + pluginDefault = [ ]; + example = [ + ".DS_Store" + "node_modules" + ]; + description = '' + List of files not to be displayed. + ''; + }; + + devicons = { + enable = defaultNullOpts.mkBool false '' + Whether to show devicons. + This requires enabling `plugins.web-devicons`. + ''; + + highlight_dirname = defaultNullOpts.mkBool false '' + Whether to highlight dirnames with devicons enabled. + ''; + }; + + mappings = defaultNullOpts.mkAttrsOf' { + type = types.rawLua; + pluginDefault = { }; + example = { + l.__raw = "require('lir').actions.edit"; + "".__raw = "require'lir.actions'.split"; + "".__raw = "require'lir.actions'.vsplit"; + "".__raw = "require'lir.actions'.tabedit"; + J.__raw = '' + function() + mark_actions.toggle_mark() + vim.cmd('normal! j') + end + ''; + }; + description = '' + Specify the table to be used for mapping. + You can also specify a function that you define yourself. + ''; + }; + + hide_cursor = defaultNullOpts.mkBool false '' + Whether to hide the cursor in lir? + + If the cursor is shown, it will be prefixed with a space. + ''; + + get_filters = defaultNullOpts.mkRaw null '' + `|lir-file-item|` function that returns a list of functions to filter for. + + They are called in order from the top of the list before being displayed on the buffer. + + Set up a function that returns a list of the following functions. + `lir_item` is `|lir-file-item|`. + + Signature: + ```lua + fun(files: lir_item[]): lir_item[] + ``` + ''; + + float = { + winblend = defaultNullOpts.mkUnsignedInt 0 '' + The degree of transparency of the window displayed by the floating window. + ''; + + win_opts = defaultNullOpts.mkAttrsOf' { + type = types.str; + pluginDefault = { + relative = "editor"; + row.__raw = "math.floor((vim.o.lines - (vim.o.lines * 0.5)) / 2) - 1"; + col.__raw = "math.floor((vim.o.lines - (vim.o.columns * 0.5)) / 2)"; + width.__raw = "math.floor(vim.o.columns * 0.5)"; + height.__raw = "math.floor(vim.o.lines * 0.5)"; + style = "minimal"; + border = "double"; + }; + example.__raw = '' + function() + local width = math.floor(vim.o.columns * 0.6) + local height = math.floor(vim.o.lines * 0.8) + return { + border = require("lir.float.helper").make_border_opts({ + "+", "─", "+", "│", "+", "─", "+", "│", + }, "Normal"), + width = width, + height = height, + row = 10, + col = math.floor((vim.o.columns - width) / 2), + } + end + ''; + description = '' + Specifies the function that returns the table to be passed as the third argument of + `|nvim_open_win()|`. + + Use this when you want to override the default configs. + ''; + }; + + curdir_window = { + enable = defaultNullOpts.mkBool false '' + Whether to show current directory window. + ''; + + highlight_dirname = defaultNullOpts.mkBool false '' + Whether to highlight a directory in the current directory window in a floating window? + ''; + }; + }; +} diff --git a/tests/test-sources/plugins/by-name/lir/default.nix b/tests/test-sources/plugins/by-name/lir/default.nix new file mode 100644 index 00000000..13d2ddd1 --- /dev/null +++ b/tests/test-sources/plugins/by-name/lir/default.nix @@ -0,0 +1,49 @@ +{ + empty = { + plugins.lir.enable = true; + }; + + defaults = { + plugins.lir = { + enable = true; + + settings = { + show_hidden_files = false; + ignore = [ ]; + devicons = { + enable = false; + highlight_dirname = false; + }; + hide_cursor = false; + on_init.__raw = "function() end"; + mappings = { }; + float = { + winblend = 0; + curdir_window = { + enable = false; + highlight_dirname = false; + }; + }; + get_filters = null; + }; + }; + }; + + example = { + plugins.lir = { + enable = true; + + settings = { + show_hidden_files = true; + devicons.enable = false; + mappings = { + "".__raw = "require'lir.actions'.edit"; + "-".__raw = "require'lir.actions'.up"; + "".__raw = "require'lir.actions'.quit"; + "@".__raw = "require'lir.actions'.cd"; + }; + hide_cursor = true; + }; + }; + }; +}