feat: make trash command more robust
parent
18885a695b
commit
274f1abdfd
|
|
@ -6,13 +6,8 @@ local fn = vim.fn
|
||||||
local cmd = vim.cmd
|
local cmd = vim.cmd
|
||||||
|
|
||||||
local function bwipeout(bufnr)
|
local function bwipeout(bufnr)
|
||||||
local bufnr_int = bufnr and vim.fn.bufnr(bufnr) or vim.fn.bufnr('%')
|
bufnr = bufnr and fn.bufnr(bufnr) or 0
|
||||||
|
vim.api.nvim_buf_delete(bufnr, { force = true })
|
||||||
if pcall(require, 'bufdelete') then
|
|
||||||
require 'bufdelete'.bufwipeout(bufnr_int)
|
|
||||||
else
|
|
||||||
vim.cmd.bwipeout(bufnr_int)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function leaveVisualMode()
|
local function leaveVisualMode()
|
||||||
|
|
@ -215,17 +210,16 @@ function M.trashFile(opts)
|
||||||
local currentFile = expand("%:p")
|
local currentFile = expand("%:p")
|
||||||
local filename = expand("%:t")
|
local filename = expand("%:t")
|
||||||
|
|
||||||
-- os.rename fails if trash is on different filesystem
|
if fileExists(trash .. filename) then
|
||||||
local success, errormsg = pcall(cmd.write, trash .. filename)
|
filename = filename .. "~"
|
||||||
if success then
|
|
||||||
success, errormsg = os.remove(currentFile)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local success, err = pcall(vim.loop.fs_rename, currentFile, trash .. filename)
|
||||||
if success then
|
if success then
|
||||||
bwipeout()
|
bwipeout()
|
||||||
vim.notify('"' .. filename .. '" deleted.')
|
vim.notify(("%q deleted"):format(filename))
|
||||||
else
|
else
|
||||||
vim.notify("Could not delete file: " .. errormsg, logError)
|
vim.notify("Could not delete file: " .. err, logError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
if vim.fn.exists("g:genghis_disable_commands") == 0 then
|
if vim.g.genghis_disable_commands then
|
||||||
vim.g.genghis_disable_commands = false
|
vim.g.genghis_disable_commands = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if not vim.g.genghis_disable_commands then
|
if not vim.g.genghis_disable_commands then
|
||||||
local command = vim.api.nvim_create_user_command
|
local command = vim.api.nvim_create_user_command
|
||||||
local genghis = require("genghis")
|
local genghis = require("genghis")
|
||||||
|
|
||||||
command("NewFromSelection", function() genghis.moveSelectionToNewFile() end, { range = true })
|
command("NewFromSelection", function() genghis.moveSelectionToNewFile() end, { range = true })
|
||||||
command("Duplicate", function() genghis.duplicateFile() end, {})
|
command("Duplicate", function() genghis.duplicateFile() end, {})
|
||||||
command("Rename", function() genghis.renameFile() end, {})
|
command("Rename", function() genghis.renameFile() end, {})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue