From 1432b7376dbf076f56e92ad6bda26e2880da6a51 Mon Sep 17 00:00:00 2001 From: Man2Dev Date: Wed, 17 Aug 2022 01:55:45 +0430 Subject: [PATCH 1/5] Add files via upload --- copyTime.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/copyTime.lua b/copyTime.lua index b412562..c7ea47f 100644 --- a/copyTime.lua +++ b/copyTime.lua @@ -23,10 +23,17 @@ local function command_exists(cmd) return exists end +local function display_servers(cmd) + local pipe = io.popen("echo $XDG_SESSION_TYPE") + exists = pipe:read() == cmd + pipe:close() + return exists +end + local function get_clipboard_cmd() - if command_exists("xclip") then + if display_servers("x11") and command_exists("xclip") then return "xclip -silent -in -selection clipboard" - elseif command_exists("wl-copy") then + elseif display_servers("wayland") and command_exists("wl-copy") then return "wl-copy" elseif command_exists("pbcopy") then return "pbcopy" @@ -40,7 +47,7 @@ local function divmod(a, b) return a / b, a % b end -local function set_clipboard(text) +local function set_clipboard(text) if platform == WINDOWS then mp.commandv("run", "powershell", "set-clipboard", text) return true From b0d59a2f84f5eec385a73a33204b3df8ac372715 Mon Sep 17 00:00:00 2001 From: Man2Dev Date: Wed, 17 Aug 2022 01:59:25 +0430 Subject: [PATCH 2/5] Add files via upload --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c1184cf..e6acec4 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Put the script `copyTime.lua` in your scripts folder, usually in: To work, the script needs: * Windows: `Powershell`. * Linux/X11: `xclip`. -* Linux/Wayland : `xclip` or `wl-clipboard`. +* Linux/Wayland : `wl-clipboard`. * MacOS: `pbcopy` (not tested). # Screenshot From 52025247aeed6239884d6d8847f12e53f19c3a91 Mon Sep 17 00:00:00 2001 From: alireza ghorbani Date: Thu, 18 Aug 2022 19:56:25 +0430 Subject: [PATCH 3/5] Specific error for command_exists added --- copyTime.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/copyTime.lua b/copyTime.lua index c7ea47f..4252035 100644 --- a/copyTime.lua +++ b/copyTime.lua @@ -20,6 +20,14 @@ local function command_exists(cmd) local pipe = io.popen("type " .. cmd .. " > /dev/null 2> /dev/null; printf \"$?\"", "r") exists = pipe:read() == "0" pipe:close() + + -- show error if command not exists + if not exists and cmd == "pbcopy" then + mp.msg.error(cmd .. " package not found! please install it (MacOS-only).") + elseif not exists then + mp.msg.error(cmd .. " package not found! please install it.") + end + return exists end @@ -38,7 +46,6 @@ local function get_clipboard_cmd() elseif command_exists("pbcopy") then return "pbcopy" else - mp.msg.error("No supported clipboard command found") return false end end From 94180c9bffeeb91e7be9529079a2ab7adafa11f1 Mon Sep 17 00:00:00 2001 From: Man2Dev Date: Wed, 28 Dec 2022 04:25:50 +0330 Subject: [PATCH 4/5] minor fixes --- copyTime.lua | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/copyTime.lua b/copyTime.lua index 4252035..12b7915 100644 --- a/copyTime.lua +++ b/copyTime.lua @@ -20,19 +20,13 @@ local function command_exists(cmd) local pipe = io.popen("type " .. cmd .. " > /dev/null 2> /dev/null; printf \"$?\"", "r") exists = pipe:read() == "0" pipe:close() - - -- show error if command not exists - if not exists and cmd == "pbcopy" then - mp.msg.error(cmd .. " package not found! please install it (MacOS-only).") - elseif not exists then - mp.msg.error(cmd .. " package not found! please install it.") - end - return exists end +-- reference for io.popen: +-- https://pubs.opengroup.org/onlinepubs/009695399/functions/popen.html local function display_servers(cmd) - local pipe = io.popen("echo $XDG_SESSION_TYPE") + local pipe = io.popen("echo $XDG_SESSION_TYPE", "r") exists = pipe:read() == cmd pipe:close() return exists @@ -46,6 +40,7 @@ local function get_clipboard_cmd() elseif command_exists("pbcopy") then return "pbcopy" else + mp.msg.error("No supported clipboard command found") return false end end @@ -89,4 +84,4 @@ if platform == UNIX then clipboard_cmd = get_clipboard_cmd() end -mp.add_key_binding("Ctrl+c", "copyTime", copyTime) +mp.add_key_binding("ALT+x", "copyTime", copyTime) From 327061bc40c8ff3b37058cbb986da28bab83c0fc Mon Sep 17 00:00:00 2001 From: Man2Dev Date: Wed, 28 Dec 2022 04:39:12 +0330 Subject: [PATCH 5/5] minor fixes --- copyTime.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/copyTime.lua b/copyTime.lua index 12b7915..5fbbe06 100644 --- a/copyTime.lua +++ b/copyTime.lua @@ -20,6 +20,14 @@ local function command_exists(cmd) local pipe = io.popen("type " .. cmd .. " > /dev/null 2> /dev/null; printf \"$?\"", "r") exists = pipe:read() == "0" pipe:close() + + -- show error if command not exists + if not exists and cmd == "pbcopy" then + mp.msg.error(cmd .. " package not found! please install it (MacOS-only).") + elseif not exists then + mp.msg.error(cmd .. " package not found! please install it.") + end + return exists end @@ -84,4 +92,4 @@ if platform == UNIX then clipboard_cmd = get_clipboard_cmd() end -mp.add_key_binding("ALT+x", "copyTime", copyTime) +mp.add_key_binding("Ctrl+c", "copyTime", copyTime)