lir.lua 2.9 KB

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