1return {
2 "nvim-neo-tree/neo-tree.nvim",
3 branch = "v3.x",
4 dependencies = {
5 "nvim-lua/plenary.nvim",
6 "MunifTanjim/nui.nvim",
7 "nvim-tree/nvim-web-devicons",
8 },
9 lazy = false,
10 config = function()
11 require("neo-tree").setup({
12 close_if_last_window = true,
13 popup_border_style = "rounded",
14 enable_git_status = true,
15 enable_diagnostics = true,
16
17 window = {
18 position = "right",
19 width = 30,
20 mappings = {
21 ["P"] = {
22 "toggle_preview",
23 config = {
24 use_float = true,
25 title = "Preview",
26 },
27 },
28 },
29 },
30
31 git_status = {
32 window = {
33 mappings = {
34 ["gd"] = "git_diff_preview",
35 },
36 },
37 commands = {
38 git_diff_preview = function(state)
39 local node = state.tree:get_node()
40 if node.type ~= "file" then
41 vim.notify("Diff only for files", vim.log.levels.ERROR)
42 return
43 end
44
45 local abs_path = node.path
46 local rel_path = vim.fn.fnamemodify(abs_path, ":~:.")
47
48 local dir = vim.fn.fnamemodify(abs_path, ":h")
49 vim.fn.system("git -C " .. vim.fn.shellescape(dir) .. " rev-parse --is-inside-work-tree")
50 if vim.v.shell_error ~= 0 then
51 vim.notify("Not a git repo", vim.log.levels.ERROR)
52 return
53 end
54
55 -- floating window geometry
56 local width = math.floor(vim.o.columns * 0.9)
57 local height = math.floor(vim.o.lines * 0.85)
58 local row = math.floor((vim.o.lines - height) / 2)
59 local col = math.floor((vim.o.columns - width) / 2)
60
61 local buf = vim.api.nvim_create_buf(false, true)
62 local win = vim.api.nvim_open_win(buf, true, {
63 relative = "editor",
64 width = width,
65 height = height,
66 row = row,
67 col = col,
68 style = "minimal",
69 border = "rounded",
70 title = " diff: " .. rel_path .. " ",
71 title_pos = "center",
72 })
73
74 vim.wo[win].winblend = 0
75
76 vim.fn.termopen(
77 "git diff --no-ext-diff --color=always -- "
78 .. vim.fn.shellescape(rel_path)
79 .. " | delta --side-by-side --paging=always"
80 )
81
82 vim.bo[buf].bufhidden = "wipe"
83 vim.bo[buf].buflisted = false
84
85 local function close()
86 if vim.api.nvim_win_is_valid(win) then
87 vim.api.nvim_win_close(win, true)
88 end
89 end
90
91 vim.keymap.set({ "n", "t" }, "q", close, { buffer = buf, silent = true })
92 vim.keymap.set({ "n", "t" }, "<Esc>", close, { buffer = buf, silent = true })
93
94 vim.cmd("startinsert")
95 end,
96 },
97 },
98
99 default_component_configs = {
100 git_status = {
101 symbols = {
102 added = "✚",
103 modified = "",
104 deleted = "✖",
105 renamed = "",
106 untracked = "",
107 ignored = "",
108 unstaged = "",
109 staged = "",
110 conflict = "",
111 },
112 },
113 },
114 filesystem = {
115 follow_current_file = {
116 enabled = true,
117 },
118 filtered_items = {
119 hide_dotfiles = false,
120 hide_gitignored = true,
121 },
122 },
123 sources = {
124 "filesystem",
125 "git_status",
126 },
127 source_selector = {
128 winbar = true,
129 statusline = false,
130 },
131 })
132 end,
133}