diff options
| author | delta <darkussdelta@gmail.com> | 2026-04-17 08:10:30 +0200 |
|---|---|---|
| committer | delta <darkussdelta@gmail.com> | 2026-04-17 08:10:30 +0200 |
| commit | a7c79cb5a04562be10347856642a80f0c4be89fc (patch) | |
| tree | 98fac95855d84f5037a1c6f44061cbe94b550600 /.config/nvim/lua/plugins/nvim-tree.lua | |
| parent | 225eeafcea67d63a608f9c666faf2a2ef014be4a (diff) | |
Diffstat (limited to '.config/nvim/lua/plugins/nvim-tree.lua')
| -rw-r--r-- | .config/nvim/lua/plugins/nvim-tree.lua | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/.config/nvim/lua/plugins/nvim-tree.lua b/.config/nvim/lua/plugins/nvim-tree.lua new file mode 100644 index 0000000..8afa105 --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-tree.lua @@ -0,0 +1,131 @@ +local state = require "state" + +local function natural_cmp(_left, _right) + local left = _left.name:lower() + local right = _right.name:lower() + + if left == right then + return false + end + + local is_l_dir = _left.type ~= "directory" + local is_r_dir = _right.type ~= "directory" + if ((is_l_dir or is_r_dir) and not (is_l_dir and is_r_dir)) then + return is_r_dir + end + + for i = 1, math.max(string.len(left), string.len(right)), 1 do + local l = string.sub(left, i, -1) + local r = string.sub(right, i, -1) + + if type(tonumber(string.sub(l, 1, 1))) == "number" and type(tonumber(string.sub(r, 1, 1))) == "number" then + local l_number = tonumber(string.match(l, "^[0-9]+")) + local r_number = tonumber(string.match(r, "^[0-9]+")) + + if l_number ~= r_number then + return l_number < r_number + end + elseif string.sub(l, 1, 1) ~= string.sub(r, 1, 1) then + return l < r + end + end +end + +return { + "nvim-tree/nvim-tree.lua", + opts = { + sort_by = function (nodes) + table.sort(nodes, natural_cmp) + end, + view = { + width = 30, + }, + renderer = { + root_folder_label = function() + return ".." + end, + indent_markers = { + enable = true, + }, + icons = { + show = { + folder_arrow = false, + }, + glyphs = { + git = { + unstaged = "-", + staged = "+", + unmerged = "", + renamed = "", + untracked = "", + deleted = "", + ignored = "", + }, + }, + }, + }, + filters = { + git_ignored = false, + }, + }, + config = function(_, opts) + local api = require "nvim-tree.api" + local Event = api.events.Event + + api.events.subscribe(Event.Ready, function() + state.nvim_tree_root = api.tree.get_nodes().absolute_path + end) + + api.events.subscribe(Event.TreeRendered, function() + state.nvim_tree_root = api.tree.get_nodes().absolute_path + end) + + require("nvim-tree").setup(vim.tbl_extend("force", opts, { + -- on_attach = function () + -- local function opts(desc) + -- return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + -- end + -- + -- local function edit_or_open() + -- local node = api.tree.get_node_under_cursor() + -- + -- if node.nodes ~= nil then + -- -- expand or collapse folder + -- api.node.open.edit() + -- else + -- -- open file + -- api.node.open.edit() + -- -- Close the tree if file was opened + -- api.tree.close() + -- end + -- end + -- + -- -- open as vsplit on current node + -- local function vsplit_preview() + -- local node = api.tree.get_node_under_cursor() + -- + -- if node.nodes ~= nil then + -- -- expand or collapse folder + -- api.node.open.edit() + -- else + -- -- open file as vsplit + -- api.node.open.vertical() + -- end + -- + -- -- Finally refocus on tree if it was lost + -- api.tree.focus() + -- end + -- + -- vim.keymap.set("n", "l", edit_or_open, opts("Edit Or Open")) + -- vim.keymap.set("n", "h", api.tree.close, opts("Close")) + -- end + -- + })) + end, + dependencies = { + "nvim-tree/nvim-web-devicons", + }, + keys = { + { "<Leader>e", "<cmd>NvimTreeToggle<CR>", desc = "Toggle nvim-tree" }, + }, +} |
