diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-06-03 23:23:49 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-06-03 23:23:49 +0200 |
commit | 7d11253a69fa759037a29bacfe791df35229e5bf (patch) | |
tree | 7c4b9ebd9b074eeee77da96d67334d10fa18ec52 /.config/mpv/scripts/copy-subs.lua | |
parent | a2d25cba38aee3c5023bcfedf3cc8cc4a1c008a9 (diff) |
add auto copying to mpv script
Diffstat (limited to '.config/mpv/scripts/copy-subs.lua')
-rw-r--r-- | .config/mpv/scripts/copy-subs.lua | 23 |
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) |