diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-06-06 17:29:57 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-06-06 17:29:57 +0900 |
| commit | 58b470132119f01883ef68411adf62f65d91a0e9 (patch) | |
| tree | 307fbb954892feeea35e6fe343032e59893df714 /ar/.config/TheSiahxyz/lua/thesiahxyz/plugins/neo-tree.lua | |
| parent | 7abaacdd7b7ebadaa6833c200eead4e84cb236d8 (diff) | |
updates
Diffstat (limited to 'ar/.config/TheSiahxyz/lua/thesiahxyz/plugins/neo-tree.lua')
| -rw-r--r-- | ar/.config/TheSiahxyz/lua/thesiahxyz/plugins/neo-tree.lua | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/ar/.config/TheSiahxyz/lua/thesiahxyz/plugins/neo-tree.lua b/ar/.config/TheSiahxyz/lua/thesiahxyz/plugins/neo-tree.lua new file mode 100644 index 0000000..b21b130 --- /dev/null +++ b/ar/.config/TheSiahxyz/lua/thesiahxyz/plugins/neo-tree.lua @@ -0,0 +1,121 @@ +return { + { + "nvim-neo-tree/neo-tree.nvim", + branch = "v3.x", + dependencies = { + "nvim-lua/plenary.nvim", + "nvim-tree/nvim-web-devicons", -- not strictly required, but recommended + "MunifTanjim/nui.nvim", + { "3rd/image.nvim", opts = {} }, -- Optional image support in preview window: See `# Preview Mode` for more information + }, + lazy = false, -- neo-tree will lazily load itself + ---@module "neo-tree" + ---@type neotree.Config? + opts = { + filesystem = { + follow_current_file = { enabled = false }, + commands = { + -- over write default 'delete' command to 'trash'. + delete = function(state) + if vim.fn.executable("trash") == 0 then + vim.api.nvim_echo({ + { "- Trash utility not installed. Make sure to install it first\n", nil }, + { "- In macOS run `brew install trash`\n", nil }, + { "- Or delete the `custom delete command` section in neo-tree", nil }, + }, false, {}) + return + end + local inputs = require("neo-tree.ui.inputs") + local path = state.tree:get_node().path + local msg = "Are you sure you want to trash " .. path + inputs.confirm(msg, function(confirmed) + if not confirmed then + return + end + + vim.fn.system({ "trash", vim.fn.fnameescape(path) }) + require("neo-tree.sources.manager").refresh(state.name) + end) + end, + -- Overwrite default 'delete_visual' command to 'trash' x n. + delete_visual = function(state, selected_nodes) + if vim.fn.executable("trash") == 0 then + vim.api.nvim_echo({ + { "- Trash utility not installed. Make sure to install it first\n", nil }, + { "- In macOS run `brew install trash`\n", nil }, + { "- Or delete the `custom delete command` section in neo-tree", nil }, + }, false, {}) + return + end + local inputs = require("neo-tree.ui.inputs") + + -- Function to get the count of items in a table + local function GetTableLen(tbl) + local len = 0 + for _ in pairs(tbl) do + len = len + 1 + end + return len + end + + local count = GetTableLen(selected_nodes) + local msg = "Are you sure you want to trash " .. count .. " files?" + inputs.confirm(msg, function(confirmed) + if not confirmed then + return + end + for _, node in ipairs(selected_nodes) do + vim.fn.system({ "trash", vim.fn.fnameescape(node.path) }) + end + require("neo-tree.sources.manager").refresh(state.name) + end) + end, + }, + }, + }, + keys = { + { "<leader>e", false }, + { "<leader>E", false }, + { + "<leader>en", + function() + local buf_name = vim.api.nvim_buf_get_name(0) + -- Function to check if NeoTree is open in any window + local function is_neo_tree_open() + for _, win in ipairs(vim.api.nvim_list_wins()) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.bo[buf].filetype == "neo-tree" then + return true + end + end + return false + end + -- Check if the current file exists + if + vim.fn.filereadable(buf_name) == 1 + or vim.fn.isdirectory(vim.fn.fnamemodify(buf_name, ":p:h")) == 1 + then + if is_neo_tree_open() then + -- Close NeoTree if it's open + vim.cmd("Neotree close") + else + -- Open NeoTree and reveal the current file + vim.cmd("Neotree reveal") + end + else + -- If the file doesn't exist, execute the logic for <leader>R + require("neo-tree.command").execute({ toggle = true, dir = vim.uv.cwd() }) + end + end, + desc = "Open neo-tree", + }, + { + "<leader>eN", + function() + require("neo-tree.command").execute({ toggle = true, dir = vim.uv.cwd() }) + end, + desc = "Open neo-tree (cwd)", + }, + }, + }, +} |
