Skip to content

Commit ac858a2

Browse files
authored
fix(run-command): handle current directory node (#1046)
Handle the node representing the current directory (the topmost node in the nvim-tree window). That node does not have the `absolute_path` set. Use `TreeExplorer.cwd` instead, similar to the logic in `change-dir`.
1 parent a3f256d commit ac858a2

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lua/nvim-tree/actions/run-command.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1+
local utils = require("nvim-tree.utils")
2+
13
local M = {}
24

5+
---Retrieves the absolute path to the node.
6+
---Safely handles the node representing the current directory
7+
---(the topmost node in the nvim-tree window)
8+
local function get_node_path(node)
9+
if node.name == ".." then
10+
return utils.path_remove_trailing(TreeExplorer.cwd)
11+
else
12+
return node.absolute_path
13+
end
14+
end
15+
316
function M.run_file_command(node)
4-
vim.api.nvim_input(": " .. node.absolute_path .. "<Home>")
17+
local node_path = get_node_path(node)
18+
vim.api.nvim_input(": " .. node_path .. "<Home>")
519
end
620

721
return M
8-

0 commit comments

Comments
 (0)