echasnovski / mini.nvim

Library of 40+ independent Lua modules improving overall Neovim (version 0.8 and higher) experience with minimal effort
MIT License
4.54k stars 175 forks source link

add skip_confirm_for_simple_edits similar to oil.nvim #874

Closed yujinyuz closed 2 months ago

yujinyuz commented 2 months ago

Contributing guidelines

Module(s)

mini.files

Description

Is it possible to add an option similar to oil.nvim skip_confirm_for_simple_edits where it does not need to confirm creating a new file and renaming a file?

echasnovski commented 2 months ago

Sorry, no: not right now and not planned. Mostly because I think it is a bad idea in long term to take away from consistency to have this kind of experience.

yujinyuz commented 2 months ago

@echasnovski alright thanks!


In case anyone is interested with this feature, I've made a slight modification to the source. What this does is it would automatically confirm when you press = but only if one action is present and the delete action is empty.

Just add vim.g.mini_files_auto_confirm_on_simple_edits variable to your config.

H.fs_actions_confirm = function(fs_actions)
  if vim.g.mini_files_auto_confirm_on_simple_edits and vim.tbl_isempty(fs_actions.delete) then
    local count = 0
    for action, paths in pairs(fs_actions) do
      if not vim.tbl_isempty(paths) then count = count + 1 end
    end

    -- Only one action is present so just automatically confirm it
    if count == 1 then return true end
  end

  local msg = table.concat(H.fs_actions_to_lines(fs_actions), '\n')
  local confirm_res = vim.fn.confirm(msg, '&Yes\n&No', 1, 'Question')
  return confirm_res == 1
end
diff --git a/lua/mini/files.lua b/lua/mini/files.lua
index 5184dea..f17432a 100644
--- a/lua/mini/files.lua
+++ b/lua/mini/files.lua
@@ -2375,6 +2375,16 @@ end

 -- File system actions --------------------------------------------------------
 H.fs_actions_confirm = function(fs_actions)
+  if vim.g.mini_files_auto_confirm_on_simple_edits and vim.tbl_isempty(fs_actions.delete) then
+    local count = 0
+    for action, paths in pairs(fs_actions) do
+      if not vim.tbl_isempty(paths) then count = count + 1 end
+    end
+
+    -- Only one action is present so just automatically confirm it
+    if count == 1 then return true end
+  end
+
   local msg = table.concat(H.fs_actions_to_lines(fs_actions), '\n')
   local confirm_res = vim.fn.confirm(msg, '&Yes\n&No', 1, 'Question')
   return confirm_res == 1