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 = {} local M = {}
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
---@return string|string[] ---@return string|string[]|false
local function setDefaultTrashCmd() local function setDefaultTrashCmd()
local osTrashCmd local osTrashCmd
local system = jit.os:lower() if jit.os == "osx" then
if system == "mac" or system == "osx" then
osTrashCmd = "trash" osTrashCmd = "trash"
elseif system == "windows" then elseif jit.os == "Windows" then
osTrashCmd = "trash" osTrashCmd = "trash"
else elseif jit.os == "Linux" then
osTrashCmd = { "gio", "trash" } osTrashCmd = { "gio", "trash" }
else
return false
end end
return osTrashCmd return osTrashCmd
end end

View File

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