From ac858a28a2ca673bbca74af005442e58e015f19e Mon Sep 17 00:00:00 2001 From: Grzegorz Rozdzialik Date: Fri, 4 Mar 2022 13:02:42 +0100 Subject: [PATCH] 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`. --- lua/nvim-tree/actions/run-command.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lua/nvim-tree/actions/run-command.lua b/lua/nvim-tree/actions/run-command.lua index 400e55e5..1c860571 100644 --- a/lua/nvim-tree/actions/run-command.lua +++ b/lua/nvim-tree/actions/run-command.lua @@ -1,8 +1,21 @@ +local utils = require("nvim-tree.utils") + local M = {} +---Retrieves the absolute path to the node. +---Safely handles the node representing the current directory +---(the topmost node in the nvim-tree window) +local function get_node_path(node) + if node.name == ".." then + return utils.path_remove_trailing(TreeExplorer.cwd) + else + return node.absolute_path + end +end + function M.run_file_command(node) - vim.api.nvim_input(": " .. node.absolute_path .. "") + local node_path = get_node_path(node) + vim.api.nvim_input(": " .. node_path .. "") end return M -