diff options
Diffstat (limited to '.config/mpv')
-rw-r--r-- | .config/mpv/input.conf | 1 | ||||
-rw-r--r-- | .config/mpv/scripts/copy-subs.lua | 23 |
2 files changed, 20 insertions, 4 deletions
diff --git a/.config/mpv/input.conf b/.config/mpv/input.conf index 825bfd5..f275370 100644 --- a/.config/mpv/input.conf +++ b/.config/mpv/input.conf @@ -1,4 +1,5 @@ ALT+j add sub-scale +0.1 ALT+k add sub-scale -0.1 ALT+c script-message-to copy_subs copy +ALT+SHIFT+c script-message-to copy_subs auto 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) |