diff --git a/doc/nvim-tree-lua.txt b/doc/nvim-tree-lua.txt index 422fedebcee..882c90b0302 100644 --- a/doc/nvim-tree-lua.txt +++ b/doc/nvim-tree-lua.txt @@ -520,6 +520,7 @@ applying configuration. }, notify = { threshold = vim.log.levels.INFO, + absolute_path = true, }, ui = { confirm = { @@ -1284,6 +1285,10 @@ Configuration for notification. `INFO:` information only e.g. file copy path confirmation. `DEBUG:` not used. + *nvim-tree.notify.absolute_path* + Whether to use absolute paths or item names in fs action notifications. + Type: `boolean`, Default: `true` + *nvim-tree.ui* General UI configuration. diff --git a/lua/nvim-tree.lua b/lua/nvim-tree.lua index efda562f1c8..74bc7f55caa 100644 --- a/lua/nvim-tree.lua +++ b/lua/nvim-tree.lua @@ -574,6 +574,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS }, notify = { threshold = vim.log.levels.INFO, + absolute_path = true, }, ui = { confirm = { diff --git a/lua/nvim-tree/actions/fs/copy-paste.lua b/lua/nvim-tree/actions/fs/copy-paste.lua index 27cc1c475e3..6c339dc00ae 100644 --- a/lua/nvim-tree/actions/fs/copy-paste.lua +++ b/lua/nvim-tree/actions/fs/copy-paste.lua @@ -80,19 +80,20 @@ end local function do_single_paste(source, dest, action_type, action_fn) local dest_stats local success, errmsg, errcode + local notify_source = notify.render_path(source) log.line("copy_paste", "do_single_paste '%s' -> '%s'", source, dest) dest_stats, errmsg, errcode = vim.loop.fs_stat(dest) if not dest_stats and errcode ~= "ENOENT" then - notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???")) + notify.error("Could not " .. action_type .. " " .. notify_source .. " - " .. (errmsg or "???")) return false, errmsg end local function on_process() success, errmsg = action_fn(source, dest) if not success then - notify.error("Could not " .. action_type .. " " .. source .. " - " .. (errmsg or "???")) + notify.error("Could not " .. action_type .. " " .. notify_source .. " - " .. (errmsg or "???")) return false, errmsg end @@ -133,15 +134,16 @@ local function add_to_clipboard(node, clip) if node.name == ".." then return end + local notify_node = notify.render_path(node.absolute_path) for idx, _node in ipairs(clip) do if _node.absolute_path == node.absolute_path then table.remove(clip, idx) - return notify.info(node.absolute_path .. " removed from clipboard.") + return notify.info(notify_node .. " removed from clipboard.") end end table.insert(clip, node) - notify.info(node.absolute_path .. " added to clipboard.") + notify.info(notify_node .. " added to clipboard.") end function M.clear_clipboard() @@ -172,7 +174,7 @@ local function do_paste(node, action_type, action_fn) local stats, errmsg, errcode = vim.loop.fs_stat(destination) if not stats and errcode ~= "ENOENT" then log.line("copy_paste", "do_paste fs_stat '%s' failed '%s'", destination, errmsg) - notify.error("Could not " .. action_type .. " " .. destination .. " - " .. (errmsg or "???")) + notify.error("Could not " .. action_type .. " " .. notify.render_path(destination) .. " - " .. (errmsg or "???")) return end local is_dir = stats and stats.type == "directory" @@ -223,13 +225,13 @@ function M.print_clipboard() if #clipboard.move > 0 then table.insert(content, "Cut") for _, item in pairs(clipboard.move) do - table.insert(content, " * " .. item.absolute_path) + table.insert(content, " * " .. (notify.render_path(item.absolute_path))) end end if #clipboard.copy > 0 then table.insert(content, "Copy") for _, item in pairs(clipboard.copy) do - table.insert(content, " * " .. item.absolute_path) + table.insert(content, " * " .. (notify.render_path(item.absolute_path))) end end diff --git a/lua/nvim-tree/actions/fs/create-file.lua b/lua/nvim-tree/actions/fs/create-file.lua index a510d30119f..a9569f6fc26 100644 --- a/lua/nvim-tree/actions/fs/create-file.lua +++ b/lua/nvim-tree/actions/fs/create-file.lua @@ -12,7 +12,7 @@ local function create_and_notify(file) events._dispatch_will_create_file(file) local ok, fd = pcall(vim.loop.fs_open, file, "w", 420) if not ok then - notify.error("Couldn't create file " .. file) + notify.error("Couldn't create file " .. notify.render_path(file)) return end vim.loop.fs_close(fd) @@ -81,7 +81,7 @@ function M.fn(node) elseif not utils.file_exists(path_to_create) then local success = vim.loop.fs_mkdir(path_to_create, 493) if not success then - notify.error("Could not create folder " .. path_to_create) + notify.error("Could not create folder " .. notify.render_path(path_to_create)) is_error = true break end @@ -89,7 +89,7 @@ function M.fn(node) end end if not is_error then - notify.info(new_file_path .. " was properly created") + notify.info(notify.render_path(new_file_path) .. " was properly created") end -- synchronously refreshes as we can't wait for the watchers diff --git a/lua/nvim-tree/actions/fs/remove-file.lua b/lua/nvim-tree/actions/fs/remove-file.lua index a8fddf22e45..d29bd21c4ae 100644 --- a/lua/nvim-tree/actions/fs/remove-file.lua +++ b/lua/nvim-tree/actions/fs/remove-file.lua @@ -74,22 +74,23 @@ end --- Remove a node, notify errors, dispatch events --- @param node table function M.remove(node) + local notify_node = notify.render_path(node.absolute_path) if node.nodes ~= nil and not node.link_to then local success = remove_dir(node.absolute_path) if not success then - return notify.error("Could not remove " .. node.name) + return notify.error("Could not remove " .. notify_node) end events._dispatch_folder_removed(node.absolute_path) else events._dispatch_will_remove_file(node.absolute_path) local success = vim.loop.fs_unlink(node.absolute_path) if not success then - return notify.error("Could not remove " .. node.name) + return notify.error("Could not remove " .. notify_node) end events._dispatch_file_removed(node.absolute_path) clear_buffer(node.absolute_path) end - notify.info(node.absolute_path .. " was properly removed.") + notify.info(notify_node .. " was properly removed.") end function M.fn(node) diff --git a/lua/nvim-tree/actions/fs/rename-file.lua b/lua/nvim-tree/actions/fs/rename-file.lua index 9e686e41dab..4436fa14894 100644 --- a/lua/nvim-tree/actions/fs/rename-file.lua +++ b/lua/nvim-tree/actions/fs/rename-file.lua @@ -20,17 +20,20 @@ local function err_fmt(from, to, reason) end function M.rename(node, to) + local notify_from = notify.render_path(node.absolute_path) + local notify_to = notify.render_path(to) + if utils.file_exists(to) then - notify.warn(err_fmt(node.absolute_path, to, "file already exists")) + notify.warn(err_fmt(notify_from, notify_to, "file already exists")) return end events._dispatch_will_rename_node(node.absolute_path, to) local success, err = vim.loop.fs_rename(node.absolute_path, to) if not success then - return notify.warn(err_fmt(node.absolute_path, to, err)) + return notify.warn(err_fmt(notify_from, notify_to, err)) end - notify.info(node.absolute_path .. " ➜ " .. to) + notify.info(notify_from .. "  " .. notify_to) utils.rename_loaded_buffers(node.absolute_path, to) events._dispatch_node_renamed(node.absolute_path, to) end diff --git a/lua/nvim-tree/notify.lua b/lua/nvim-tree/notify.lua index e42a4d86e08..32f4e50ce1b 100644 --- a/lua/nvim-tree/notify.lua +++ b/lua/nvim-tree/notify.lua @@ -2,6 +2,7 @@ local M = {} local config = { threshold = vim.log.levels.INFO, + absolute_path = true, } local modes = { @@ -30,9 +31,18 @@ do end end +function M.render_path(path) + if config.absolute_path then + return path + else + return vim.fn.fnamemodify(path .. "/", ":h:t") + end +end + function M.setup(opts) opts = opts or {} config.threshold = opts.notify.threshold or vim.log.levels.INFO + config.absolute_path = opts.notify.absolute_path end return M