improv: use `vim.uv` for os-detection

remotes/origin/HEAD
Chris Grieser 2024-05-21 14:27:48 +02:00
parent 7dabb8b0f5
commit e4bb1a3a53
1 changed files with 5 additions and 4 deletions

View File

@ -230,12 +230,13 @@ end
---@param opts? { trashCmd: string } ---@param opts? { trashCmd: string }
function M.trashFile(opts) function M.trashFile(opts)
local userCmd = opts and opts.trashCmd local userCmd = opts and opts.trashCmd
local system = vim.uv.os_uname().sysname:lower()
local defaultCmd local defaultCmd
if fn.has("mac") == 1 then defaultCmd = "trash" end if system == "darwin" then defaultCmd = "trash" end
if fn.has("linux") == 1 then defaultCmd = "trash" end if system:find("windows") then defaultCmd = "trash" end
if fn.has("win32") == 1 then defaultCmd = "gio trash" end if system:find("linux") then defaultCmd = "gio trash" end
local trashCmd = userCmd or defaultCmd local trashCmd = userCmd or defaultCmd
assert(defaultCmd, "Unknown operating system & no custom trashCmd provided.") assert(defaultCmd, "Unknown operating system. Please provide a custom trashCmd.")
local trashArgs = vim.split(trashCmd, " ") local trashArgs = vim.split(trashCmd, " ")
local oldFilePath = vim.api.nvim_buf_get_name(0) local oldFilePath = vim.api.nvim_buf_get_name(0)