lir.lua 2.8 KB

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