lir.lua 2.7 KB

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