🐛 Fixed Linux clipboard

This commit is contained in:
TheColorman 2023-06-21 16:24:46 +02:00
parent b2dad49a2c
commit 77eb47c652
No known key found for this signature in database
GPG key ID: A9C799E05AC900AF

View file

@ -533,26 +533,24 @@ function main_menu:upload_catbox()
end end
if os_type == "linux" then if os_type == "linux" then
local session_type = io.popen('/bin/sh -c "echo $XDG_SESSION_TYPE"'):read("*a") local cb_x11 = string.find(subprocess({
"whereis", "xclip"
}).stdout, "/")
local cb_wayland = string.find(subprocess({
"whereis", "wl-copy"
}).stdout, "/")
local cb if cb_x11 == nil and cb_wayland == nil then
if session_type == "x11\n" then notify("Failed to copy URL to clipboard, trying to open in browser instead.\n(Make sure xclip or wl-clipboard is installed)", "warn", 6)
local clipboard_command = {
"xclip", "-sel", "clip"
}
cb = subprocess(clipboard_command, r.stdout)
else
-- wl-copy is from wl-clipboard
local clipboard_command = {
"wl-copy", r.stdout
}
cb = subprocess(clipboard_command)
end
if cb.status ~= 0 then
notify("Failed to copy URL to clipboard, trying to open in browser instead. (Make sure xclip or wl-clipboard is installed)", "warn", 4)
mp.commandv('run', open_utility, r.stdout) mp.commandv('run', open_utility, r.stdout)
return return
end end
if cb_x11 ~= nil then
mp.command("run /bin/sh -c \"echo " .. r.stdout .. " | xclip -sel clip\"")
elseif cb_wayland ~= nil then
mp.command("run wl-copy " .. r.stdout)
end
end end
notify("Done! Copied URL to clipboard.", "info", 2) notify("Done! Copied URL to clipboard.", "info", 2)