lir.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. local M = {}
  2. M.config = function()
  3. lvim.builtin.lir = {
  4. active = true,
  5. on_config_done = nil,
  6. icon = "",
  7. }
  8. local status_ok, _ = pcall(require, "lir")
  9. if not status_ok then
  10. return
  11. end
  12. local actions = require "lir.actions"
  13. local mark_actions = require "lir.mark.actions"
  14. local clipboard_actions = require "lir.clipboard.actions"
  15. lvim.builtin.lir = vim.tbl_extend("force", lvim.builtin.lir, {
  16. show_hidden_files = false,
  17. devicons_enable = true,
  18. mappings = {
  19. ["l"] = actions.edit,
  20. ["<CR>"] = actions.edit,
  21. ["<C-s>"] = actions.split,
  22. ["v"] = actions.vsplit,
  23. ["<C-t>"] = actions.tabedit,
  24. ["h"] = actions.up,
  25. ["q"] = actions.quit,
  26. ["A"] = actions.mkdir,
  27. ["a"] = actions.newfile,
  28. ["r"] = actions.rename,
  29. ["@"] = actions.cd,
  30. ["Y"] = actions.yank_path,
  31. ["i"] = actions.toggle_show_hidden,
  32. ["d"] = actions.delete,
  33. ["J"] = function()
  34. mark_actions.toggle_mark()
  35. vim.cmd "normal! j"
  36. end,
  37. ["c"] = clipboard_actions.copy,
  38. ["x"] = clipboard_actions.cut,
  39. ["p"] = clipboard_actions.paste,
  40. },
  41. float = {
  42. winblend = 0,
  43. curdir_window = {
  44. enable = false,
  45. highlight_dirname = true,
  46. },
  47. -- -- You can define a function that returns a table to be passed as the third
  48. -- -- argument of nvim_open_win().
  49. win_opts = function()
  50. local width = math.floor(vim.o.columns * 0.7)
  51. local height = math.floor(vim.o.lines * 0.7)
  52. return {
  53. border = "rounded",
  54. width = width,
  55. height = height,
  56. -- row = 1,
  57. -- col = math.floor((vim.o.columns - width) / 2),
  58. }
  59. end,
  60. },
  61. hide_cursor = false,
  62. on_init = function()
  63. -- use visual mode
  64. vim.api.nvim_buf_set_keymap(
  65. 0,
  66. "x",
  67. "J",
  68. ':<C-u>lua require"lir.mark.actions".toggle_mark("v")<CR>',
  69. { noremap = true, silent = true }
  70. )
  71. -- echo cwd
  72. -- vim.api.nvim_echo({ { vim.fn.expand "%:p", "Normal" } }, false, {})
  73. end,
  74. })
  75. end
  76. function M.icon_setup()
  77. local function get_hl_by_name(name)
  78. local ret = vim.api.nvim_get_hl_by_name(name.group, true)
  79. return string.format("#%06x", ret[name.property])
  80. end
  81. local found, icon_hl = pcall(get_hl_by_name, { group = "NvimTreeFolderIcon", property = "foreground" })
  82. if not found then
  83. icon_hl = "#42A5F5"
  84. end
  85. reload("nvim-web-devicons").set_icon {
  86. lir_folder_icon = {
  87. icon = lvim.builtin.lir.icon,
  88. color = icon_hl,
  89. name = "LirFolderNode",
  90. },
  91. }
  92. end
  93. function M.setup()
  94. local status_ok, lir = pcall(reload, "lir")
  95. if not status_ok then
  96. return
  97. end
  98. lir.setup(lvim.builtin.lir)
  99. if lvim.builtin.lir.on_config_done then
  100. lvim.builtin.lir.on_config_done(lir)
  101. end
  102. end
  103. return M