fix(trashCmd): handle unknown operating system

remotes/origin/HEAD
Chris Grieser 2024-10-28 20:10:06 +01:00
parent e04857f290
commit 081b0c13cf
2 changed files with 11 additions and 12 deletions

View File

@ -1,16 +1,17 @@
local M = {}
--------------------------------------------------------------------------------
---@return string|string[]
---@return string|string[]|false
local function setDefaultTrashCmd()
local osTrashCmd
local system = jit.os:lower()
if system == "mac" or system == "osx" then
if jit.os == "osx" then
osTrashCmd = "trash"
elseif system == "windows" then
elseif jit.os == "Windows" then
osTrashCmd = "trash"
else
elseif jit.os == "Linux" then
osTrashCmd = { "gio", "trash" }
else
return false
end
return osTrashCmd
end

View File

@ -13,19 +13,17 @@ function M.chmodx()
vim.cmd.edit() -- reload the file
end
function M.trashFile(opts)
---DEPRECATION
if opts then
u.notify("The `trashCmd` option has been moved to the setup call.", "warn")
return
end
function M.trashFile()
vim.cmd("silent! update")
local oldFilePath = vim.api.nvim_buf_get_name(0)
local oldName = vim.fs.basename(oldFilePath)
-- execute the trash command
local trashCmd = require("genghis.config").config.trashCmd
if not trashCmd then
u.notify("Unknown operating system. Please provide a custom `trashCmd`.", "warn")
return
end
if type(trashCmd) == "string" then trashCmd = { trashCmd } end
table.insert(trashCmd, oldFilePath)
local result = vim.system(trashCmd):wait()