blob: 3b8d15fb1894b307aa3df59c8fcb807208010a2d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
_G.auto = false
function copy()
local sub = mp.get_property("sub-text")
if sub then
-- remove some specific unicode characters
sub = sub:gsub('\u{27a1}', '')
sub = sub:gsub('\u{fffd}', '')
sub = sub:gsub('\u{3013}', '')
sub = sub:gsub('\n', ' ') -- replace newlines with space
sub = sub:gsub('\'', '\'\\\'\'') -- escape single quotes
os.execute("echo '" .. sub .. "' | xclip -selection clipboard -i")
end
end
function autocopy()
if _G.auto == false then return end
copy()
end
function toggle_autocopy()
_G.auto = not _G.auto
mp.osd_message("autocopy " .. (_G.auto and "on" or "off"))
end
mp.add_key_binding(nil, "copy", copy)
mp.observe_property("sub-text", "string", autocopy)
mp.add_key_binding(nil, "auto", toggle_autocopy)
|