Skip to content

Commit

Permalink
fix(trashCmd): handle unknown operating system
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Oct 28, 2024
1 parent e04857f commit 081b0c1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
11 changes: 6 additions & 5 deletions lua/genghis/config.lua
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 5 additions & 7 deletions lua/genghis/operations/other.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 081b0c1

Please sign in to comment.