aboutsummaryrefslogtreecommitdiff
path: root/.config/mpv/scripts/copy-subs.lua
diff options
context:
space:
mode:
Diffstat (limited to '.config/mpv/scripts/copy-subs.lua')
-rw-r--r--.config/mpv/scripts/copy-subs.lua23
1 files changed, 19 insertions, 4 deletions
diff --git a/.config/mpv/scripts/copy-subs.lua b/.config/mpv/scripts/copy-subs.lua
index ae0aded..32ae7ef 100644
--- a/.config/mpv/scripts/copy-subs.lua
+++ b/.config/mpv/scripts/copy-subs.lua
@@ -1,9 +1,24 @@
-function copy_sub()
- sub = mp.get_property("sub-text", "string")
- if sub and sub ~= '' then
+_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
-mp.add_key_binding(nil, "copy", copy_sub)
+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)