aboutsummaryrefslogtreecommitdiff
path: root/.config/mpv/scripts/copy-subs.lua
blob: 32ae7ef6594e2059bd484bf31b95822374d480b6 (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
_G.auto = false

function copy()
	local sub = mp.get_property("sub-text")
	if sub then
		os.execute("echo '" .. sub:gsub('\'', '\'\\\'\'') .. "' | 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)