feat(#2270): add notify.absolute_path - show file or absolute path (default) names with notifications (#2286)
Co-authored-by: Alexander Courtis <alex@courtis.org>
This commit is contained in:
parent
7aff29d755
commit
3cc698b35b
@ -520,6 +520,7 @@ applying configuration.
|
|||||||
},
|
},
|
||||||
notify = {
|
notify = {
|
||||||
threshold = vim.log.levels.INFO,
|
threshold = vim.log.levels.INFO,
|
||||||
|
absolute_path = true,
|
||||||
},
|
},
|
||||||
ui = {
|
ui = {
|
||||||
confirm = {
|
confirm = {
|
||||||
@ -1284,6 +1285,10 @@ Configuration for notification.
|
|||||||
`INFO:` information only e.g. file copy path confirmation.
|
`INFO:` information only e.g. file copy path confirmation.
|
||||||
`DEBUG:` not used.
|
`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*
|
*nvim-tree.ui*
|
||||||
General UI configuration.
|
General UI configuration.
|
||||||
|
|
||||||
|
|||||||
@ -574,6 +574,7 @@ local DEFAULT_OPTS = { -- BEGIN_DEFAULT_OPTS
|
|||||||
},
|
},
|
||||||
notify = {
|
notify = {
|
||||||
threshold = vim.log.levels.INFO,
|
threshold = vim.log.levels.INFO,
|
||||||
|
absolute_path = true,
|
||||||
},
|
},
|
||||||
ui = {
|
ui = {
|
||||||
confirm = {
|
confirm = {
|
||||||
|
|||||||
@ -80,19 +80,20 @@ end
|
|||||||
local function do_single_paste(source, dest, action_type, action_fn)
|
local function do_single_paste(source, dest, action_type, action_fn)
|
||||||
local dest_stats
|
local dest_stats
|
||||||
local success, errmsg, errcode
|
local success, errmsg, errcode
|
||||||
|
local notify_source = notify.render_path(source)
|
||||||
|
|
||||||
log.line("copy_paste", "do_single_paste '%s' -> '%s'", source, dest)
|
log.line("copy_paste", "do_single_paste '%s' -> '%s'", source, dest)
|
||||||
|
|
||||||
dest_stats, errmsg, errcode = vim.loop.fs_stat(dest)
|
dest_stats, errmsg, errcode = vim.loop.fs_stat(dest)
|
||||||
if not dest_stats and errcode ~= "ENOENT" then
|
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
|
return false, errmsg
|
||||||
end
|
end
|
||||||
|
|
||||||
local function on_process()
|
local function on_process()
|
||||||
success, errmsg = action_fn(source, dest)
|
success, errmsg = action_fn(source, dest)
|
||||||
if not success then
|
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
|
return false, errmsg
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -133,15 +134,16 @@ local function add_to_clipboard(node, clip)
|
|||||||
if node.name == ".." then
|
if node.name == ".." then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local notify_node = notify.render_path(node.absolute_path)
|
||||||
|
|
||||||
for idx, _node in ipairs(clip) do
|
for idx, _node in ipairs(clip) do
|
||||||
if _node.absolute_path == node.absolute_path then
|
if _node.absolute_path == node.absolute_path then
|
||||||
table.remove(clip, idx)
|
table.remove(clip, idx)
|
||||||
return notify.info(node.absolute_path .. " removed from clipboard.")
|
return notify.info(notify_node .. " removed from clipboard.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.insert(clip, node)
|
table.insert(clip, node)
|
||||||
notify.info(node.absolute_path .. " added to clipboard.")
|
notify.info(notify_node .. " added to clipboard.")
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.clear_clipboard()
|
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)
|
local stats, errmsg, errcode = vim.loop.fs_stat(destination)
|
||||||
if not stats and errcode ~= "ENOENT" then
|
if not stats and errcode ~= "ENOENT" then
|
||||||
log.line("copy_paste", "do_paste fs_stat '%s' failed '%s'", destination, errmsg)
|
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
|
return
|
||||||
end
|
end
|
||||||
local is_dir = stats and stats.type == "directory"
|
local is_dir = stats and stats.type == "directory"
|
||||||
@ -223,13 +225,13 @@ function M.print_clipboard()
|
|||||||
if #clipboard.move > 0 then
|
if #clipboard.move > 0 then
|
||||||
table.insert(content, "Cut")
|
table.insert(content, "Cut")
|
||||||
for _, item in pairs(clipboard.move) do
|
for _, item in pairs(clipboard.move) do
|
||||||
table.insert(content, " * " .. item.absolute_path)
|
table.insert(content, " * " .. (notify.render_path(item.absolute_path)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #clipboard.copy > 0 then
|
if #clipboard.copy > 0 then
|
||||||
table.insert(content, "Copy")
|
table.insert(content, "Copy")
|
||||||
for _, item in pairs(clipboard.copy) do
|
for _, item in pairs(clipboard.copy) do
|
||||||
table.insert(content, " * " .. item.absolute_path)
|
table.insert(content, " * " .. (notify.render_path(item.absolute_path)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ local function create_and_notify(file)
|
|||||||
events._dispatch_will_create_file(file)
|
events._dispatch_will_create_file(file)
|
||||||
local ok, fd = pcall(vim.loop.fs_open, file, "w", 420)
|
local ok, fd = pcall(vim.loop.fs_open, file, "w", 420)
|
||||||
if not ok then
|
if not ok then
|
||||||
notify.error("Couldn't create file " .. file)
|
notify.error("Couldn't create file " .. notify.render_path(file))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
vim.loop.fs_close(fd)
|
vim.loop.fs_close(fd)
|
||||||
@ -81,7 +81,7 @@ function M.fn(node)
|
|||||||
elseif not utils.file_exists(path_to_create) then
|
elseif not utils.file_exists(path_to_create) then
|
||||||
local success = vim.loop.fs_mkdir(path_to_create, 493)
|
local success = vim.loop.fs_mkdir(path_to_create, 493)
|
||||||
if not success then
|
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
|
is_error = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@ -89,7 +89,7 @@ function M.fn(node)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not is_error then
|
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
|
end
|
||||||
|
|
||||||
-- synchronously refreshes as we can't wait for the watchers
|
-- synchronously refreshes as we can't wait for the watchers
|
||||||
|
|||||||
@ -74,22 +74,23 @@ end
|
|||||||
--- Remove a node, notify errors, dispatch events
|
--- Remove a node, notify errors, dispatch events
|
||||||
--- @param node table
|
--- @param node table
|
||||||
function M.remove(node)
|
function M.remove(node)
|
||||||
|
local notify_node = notify.render_path(node.absolute_path)
|
||||||
if node.nodes ~= nil and not node.link_to then
|
if node.nodes ~= nil and not node.link_to then
|
||||||
local success = remove_dir(node.absolute_path)
|
local success = remove_dir(node.absolute_path)
|
||||||
if not success then
|
if not success then
|
||||||
return notify.error("Could not remove " .. node.name)
|
return notify.error("Could not remove " .. notify_node)
|
||||||
end
|
end
|
||||||
events._dispatch_folder_removed(node.absolute_path)
|
events._dispatch_folder_removed(node.absolute_path)
|
||||||
else
|
else
|
||||||
events._dispatch_will_remove_file(node.absolute_path)
|
events._dispatch_will_remove_file(node.absolute_path)
|
||||||
local success = vim.loop.fs_unlink(node.absolute_path)
|
local success = vim.loop.fs_unlink(node.absolute_path)
|
||||||
if not success then
|
if not success then
|
||||||
return notify.error("Could not remove " .. node.name)
|
return notify.error("Could not remove " .. notify_node)
|
||||||
end
|
end
|
||||||
events._dispatch_file_removed(node.absolute_path)
|
events._dispatch_file_removed(node.absolute_path)
|
||||||
clear_buffer(node.absolute_path)
|
clear_buffer(node.absolute_path)
|
||||||
end
|
end
|
||||||
notify.info(node.absolute_path .. " was properly removed.")
|
notify.info(notify_node .. " was properly removed.")
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.fn(node)
|
function M.fn(node)
|
||||||
|
|||||||
@ -20,17 +20,20 @@ local function err_fmt(from, to, reason)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.rename(node, to)
|
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
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
events._dispatch_will_rename_node(node.absolute_path, to)
|
events._dispatch_will_rename_node(node.absolute_path, to)
|
||||||
local success, err = vim.loop.fs_rename(node.absolute_path, to)
|
local success, err = vim.loop.fs_rename(node.absolute_path, to)
|
||||||
if not success then
|
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
|
end
|
||||||
notify.info(node.absolute_path .. " ➜ " .. to)
|
notify.info(notify_from .. " " .. notify_to)
|
||||||
utils.rename_loaded_buffers(node.absolute_path, to)
|
utils.rename_loaded_buffers(node.absolute_path, to)
|
||||||
events._dispatch_node_renamed(node.absolute_path, to)
|
events._dispatch_node_renamed(node.absolute_path, to)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,6 +2,7 @@ local M = {}
|
|||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
threshold = vim.log.levels.INFO,
|
threshold = vim.log.levels.INFO,
|
||||||
|
absolute_path = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
local modes = {
|
local modes = {
|
||||||
@ -30,9 +31,18 @@ do
|
|||||||
end
|
end
|
||||||
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)
|
function M.setup(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
config.threshold = opts.notify.threshold or vim.log.levels.INFO
|
config.threshold = opts.notify.threshold or vim.log.levels.INFO
|
||||||
|
config.absolute_path = opts.notify.absolute_path
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user