Commit: 72b9ec2c280c9b28f881b98c0f153ea42e79ee00
Parent: eb0b9e61352e549febd0df814dc2f0608c109cbb
Author: Ren Tatsumoto
Date: Thu, 1 Oct 2020 23:14:47 +0300
new clipboard inserter that doesn't rely on a separate shell script
this should improve portability
Diffstat:
1 file changed, 17 insertions(+), 14 deletions(-)
diff --git a/subs2srs.lua b/subs2srs.lua
@@ -164,20 +164,6 @@ local function escape_quotes(str)
return str:gsub('"', '"')
end
-local function copy_to_clipboard(_, text)
- -- roughly called as in fn(name, mp.get_property_string(name))
- if is_emptystring(text) then
- return
- end
-
- local toclip_path = os.getenv("HOME") .. '/.config/mpv/scripts/subs2srs/toclip.sh'
- mp.commandv("run", "sh", toclip_path, text)
-end
-
-local function copy_sub_to_clipboard()
- copy_to_clipboard("copy-on-demand", mp.get_property("sub-text"))
-end
-
local function contains_non_latin_letters(str)
return str:match("[^%c%p%s%w]")
end
@@ -197,6 +183,23 @@ local function trim(str)
return str
end
+local copy_to_clipboard = (function()
+ local clip_filepath = '/tmp/mpvacious_clipboard'
+ mp.register_event('shutdown', function() os.remove(clip_filepath) end)
+
+ return function(_, text)
+ if is_emptystring(text) then
+ return
+ end
+ assert(io.open(clip_filepath, "w")):write(text):close()
+ mp.commandv("run", "xclip", "-selection", "clipboard", clip_filepath)
+ end
+end)()
+
+local function copy_sub_to_clipboard()
+ copy_to_clipboard("copy-on-demand", mp.get_property("sub-text"))
+end
+
local function human_readable_time(seconds)
if type(seconds) ~= 'number' or seconds < 0 then
return 'empty'