diff --git a/lua/genghis.lua b/lua/genghis.lua index 8913ec0..6c962d0 100644 --- a/lua/genghis.lua +++ b/lua/genghis.lua @@ -6,13 +6,8 @@ local fn = vim.fn local cmd = vim.cmd local function bwipeout(bufnr) - local bufnr_int = bufnr and vim.fn.bufnr(bufnr) or vim.fn.bufnr('%') - - if pcall(require, 'bufdelete') then - require 'bufdelete'.bufwipeout(bufnr_int) - else - vim.cmd.bwipeout(bufnr_int) - end + bufnr = bufnr and fn.bufnr(bufnr) or 0 + vim.api.nvim_buf_delete(bufnr, { force = true }) end local function leaveVisualMode() @@ -215,17 +210,16 @@ function M.trashFile(opts) local currentFile = expand("%:p") local filename = expand("%:t") - -- os.rename fails if trash is on different filesystem - local success, errormsg = pcall(cmd.write, trash .. filename) - if success then - success, errormsg = os.remove(currentFile) + if fileExists(trash .. filename) then + filename = filename .. "~" end + local success, err = pcall(vim.loop.fs_rename, currentFile, trash .. filename) if success then bwipeout() - vim.notify('"' .. filename .. '" deleted.') + vim.notify(("%q deleted"):format(filename)) else - vim.notify("Could not delete file: " .. errormsg, logError) + vim.notify("Could not delete file: " .. err, logError) end end diff --git a/plugin/genghis.lua b/plugin/genghis.lua index b38bb91..26d806b 100644 --- a/plugin/genghis.lua +++ b/plugin/genghis.lua @@ -1,18 +1,17 @@ -if vim.fn.exists("g:genghis_disable_commands") == 0 then - vim.g.genghis_disable_commands = false +if vim.g.genghis_disable_commands then + vim.g.genghis_disable_commands = false end if not vim.g.genghis_disable_commands then - local command = vim.api.nvim_create_user_command - local genghis = require("genghis") - - command("NewFromSelection", function() genghis.moveSelectionToNewFile() end, { range = true }) - command("Duplicate", function() genghis.duplicateFile() end, {}) - command("Rename", function() genghis.renameFile() end, {}) - command("Trash", function() genghis.trashFile() end, {}) - command("Move", function() genghis.moveAndRenameFile() end, {}) - command("CopyFilename", function() genghis.copyFilename() end, {}) - command("CopyFilepath", function() genghis.copyFilepath() end, {}) - command("Chmodx", function() genghis.chmodx() end, {}) - command("New", function() genghis.createNewFile() end, {}) + local command = vim.api.nvim_create_user_command + local genghis = require("genghis") + command("NewFromSelection", function() genghis.moveSelectionToNewFile() end, { range = true }) + command("Duplicate", function() genghis.duplicateFile() end, {}) + command("Rename", function() genghis.renameFile() end, {}) + command("Trash", function() genghis.trashFile() end, {}) + command("Move", function() genghis.moveAndRenameFile() end, {}) + command("CopyFilename", function() genghis.copyFilename() end, {}) + command("CopyFilepath", function() genghis.copyFilepath() end, {}) + command("Chmodx", function() genghis.chmodx() end, {}) + command("New", function() genghis.createNewFile() end, {}) end