From 77eb47c652c8f042720d0591a0bf14c0d2a24199 Mon Sep 17 00:00:00 2001 From: TheColorman Date: Wed, 21 Jun 2023 16:24:46 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20Linux=20clipboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- videoclip.lua | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/videoclip.lua b/videoclip.lua index f468e89..6ff9a79 100644 --- a/videoclip.lua +++ b/videoclip.lua @@ -533,26 +533,24 @@ function main_menu:upload_catbox() end 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 session_type == "x11\n" then - 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) + if cb_x11 == nil and cb_wayland == nil 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) mp.commandv('run', open_utility, r.stdout) return 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 notify("Done! Copied URL to clipboard.", "info", 2)