diff --git a/lua/plugins/mini-files.lua b/lua/plugins/mini-files.lua index 38dfb8f..c7e5830 100644 --- a/lua/plugins/mini-files.lua +++ b/lua/plugins/mini-files.lua @@ -41,8 +41,12 @@ local function add_entry(force_dir) local state = mf.get_explorer_state() if state == nil then return end local dir = state.branch[state.depth_focus] + -- show where the entry will land: cwd-relative when inside, else ~-relative + -- (branch paths can carry a trailing slash, which defeats the `:.` reduce) + local norm = dir:gsub("(.)/+$", "%1") + local label = norm == vim.uv.cwd() and "." or vim.fn.fnamemodify(norm, ":~:.") require("snacks").input({ - prompt = force_dir and "New directory" or "New file", + prompt = (force_dir and "New directory in %s/" or "New file in %s/"):format(label), }, function(name) if name == nil or name == "" then return end vim.schedule(function() @@ -67,6 +71,26 @@ local function add_entry(force_dir) end) end +--- `d`: delete the entry under cursor after a quick Snacks.input confirm. +--- Deletes directly on disk, then MiniFiles.synchronize() refreshes the +--- explorer (external change -> no second mini.files dialog). +--- Buffer-edit deletion (visual-select + d + `=`) still works for bulk ops. +local function delete_entry() + local mf = require "mini.files" + local entry = mf.get_fs_entry() + if entry == nil then return end + local suffix = entry.fs_type == "directory" and "/" or "" + require("snacks").input({ + prompt = ("Delete %s%s? [y/N]"):format(entry.name, suffix), + }, function(answer) + if answer == nil or not vim.tbl_contains({ "y", "yes" }, answer:lower()) then return end + vim.schedule(function() + vim.fn.delete(entry.path, "rf") + mf.synchronize() + end) + end) +end + ---@type LazySpec return { { @@ -105,6 +129,10 @@ return { options = { -- take over `nvim