浏览代码

feat: add lir.nvim (#3031)

kylo252 2 年之前
父节点
当前提交
77fdcd43cb
共有 3 个文件被更改,包括 115 次插入0 次删除
  1. 1 0
      lua/lvim/core/builtins/init.lua
  2. 107 0
      lua/lvim/core/lir.lua
  3. 7 0
      lua/lvim/plugins.lua

+ 1 - 0
lua/lvim/core/builtins/init.lua

@@ -9,6 +9,7 @@ local builtins = {
   "lvim.core.telescope",
   "lvim.core.telescope",
   "lvim.core.treesitter",
   "lvim.core.treesitter",
   "lvim.core.nvimtree",
   "lvim.core.nvimtree",
+  "lvim.core.lir",
   "lvim.core.project",
   "lvim.core.project",
   "lvim.core.bufferline",
   "lvim.core.bufferline",
   "lvim.core.autopairs",
   "lvim.core.autopairs",

+ 107 - 0
lua/lvim/core/lir.lua

@@ -0,0 +1,107 @@
+local M = {}
+
+local Log = require "lvim.core.log"
+M.config = function()
+  lvim.builtin.lir = {
+    active = false,
+    on_config_done = nil,
+  }
+
+  local status_ok, actions = pcall(require, "lir.actions")
+  if not status_ok then
+    return
+  end
+
+  local mark_actions = require "lir.mark.actions"
+  local clipboard_actions = require "lir.clipboard.actions"
+  lvim.builtin.lir = vim.tbl_extend("force", lvim.builtin.lir, {
+    setup = {
+      show_hidden_files = false,
+      devicons_enable = true,
+      mappings = {
+        ["l"] = actions.edit,
+        ["<CR>"] = actions.edit,
+        ["<C-s>"] = actions.split,
+        ["v"] = actions.vsplit,
+        ["<C-t>"] = actions.tabedit,
+
+        ["h"] = actions.up,
+        ["q"] = actions.quit,
+
+        ["A"] = actions.mkdir,
+        ["a"] = actions.newfile,
+        ["r"] = actions.rename,
+        ["@"] = actions.cd,
+        ["Y"] = actions.yank_path,
+        ["i"] = actions.toggle_show_hidden,
+        ["d"] = actions.delete,
+
+        ["J"] = function()
+          mark_actions.toggle_mark()
+          vim.cmd "normal! j"
+        end,
+        ["c"] = clipboard_actions.copy,
+        ["x"] = clipboard_actions.cut,
+        ["p"] = clipboard_actions.paste,
+      },
+      float = {
+        winblend = 0,
+        curdir_window = {
+          enable = false,
+          highlight_dirname = true,
+        },
+
+        -- You can define a function that returns a table to be passed as the third
+        -- argument of nvim_open_win().
+        win_opts = function()
+          local width = math.floor(vim.o.columns * 0.7)
+          local height = math.floor(vim.o.lines * 0.7)
+          return {
+            border = "rounded",
+            width = width,
+            height = height,
+            -- row = 1,
+            -- col = math.floor((vim.o.columns - width) / 2),
+          }
+        end,
+      },
+      hide_cursor = false,
+      on_init = function()
+        -- use visual mode
+        vim.api.nvim_buf_set_keymap(
+          0,
+          "x",
+          "J",
+          ':<C-u>lua require"lir.mark.actions".toggle_mark("v")<CR>',
+          { noremap = true, silent = true }
+        )
+        -- echo cwd
+        -- vim.api.nvim_echo({ { vim.fn.expand "%:p", "Normal" } }, false, {})
+      end,
+    },
+    icons = {
+      lir_folder_icon = {
+        icon = "",
+        -- color = "#7ebae4",
+        -- color = "#569CD6",
+        color = "#42A5F5",
+        name = "LirFolderNode",
+      },
+    },
+  })
+end
+
+function M.setup()
+  if lvim.builtin.nvimtree.active then
+    Log:warn "Unable to configure lir while nvimtree is active! Please set 'lvim.builtin.nvimtree.active=false'"
+    return
+  end
+  local lir = require "lir"
+  lir.setup(lvim.builtin.lir.setup)
+  require("nvim-web-devicons").set_icon(lvim.builtin.lir.icons)
+
+  if lvim.builtin.lir.on_config_done then
+    lvim.builtin.lir.on_config_done(lir)
+  end
+end
+return M

+ 7 - 0
lua/lvim/plugins.lua

@@ -139,6 +139,13 @@ local core_plugins = {
     end,
     end,
     disable = not lvim.builtin.nvimtree.active,
     disable = not lvim.builtin.nvimtree.active,
   },
   },
+  {
+    "christianchiarulli/lir.nvim",
+    config = function()
+      require("lvim.core.lir").setup()
+    end,
+    disable = not lvim.builtin.lir.active,
+  },
 
 
   {
   {
     "lewis6991/gitsigns.nvim",
     "lewis6991/gitsigns.nvim",