Commit: 8603368c51699208e3d3c44d8acb34c95e5ebc7a
Parent: 6472e303c9e98cf94b0c39d2b995c79ea2072346
Author: Ren Tatsumoto
Date: Tue, 8 Sep 2020 05:40:17 +0300
ctrl+c to copy sub to clipboard on demand
Diffstat:
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
@@ -116,6 +116,7 @@ These bindings work everywhere, even if the menu (covered later) is not envoked.
* `Ctrl+e` - Export a card with the currently visible subtitle line on the front.
Use this when your subs are perfectly timed and the target sentence doesn't span multiple subs.
* `Ctrl+h` - Seek to the start of the currently visible subtitle. Use it if you missed something.
+* `Ctrl+c` - Copy current subtitle string to the system clipboard. For automatic copying see `advanced menu`.
### Menu options
* `a` - Open `advanced menu` with a list of all available keybindings.
diff --git a/subs2srs.lua b/subs2srs.lua
@@ -139,17 +139,18 @@ local function escape_quotes(str)
return str:gsub('"', '"')
end
-local function copy_to_clipboard(text)
+local function copy_to_clipboard(_, text)
+ -- roughly called as in fn(name, mp.get_property_string(name))
+ if is_emptystring(text) then
+ return
+ end
+
local toclip_path = os.getenv("HOME") .. '/.config/mpv/scripts/subs2srs/toclip.sh'
mp.commandv("run", "sh", toclip_path, text)
end
-local function set_clipboard(_, sub)
- -- roughly called as in fn(name, mp.get_property_string(name))
- if is_emptystring(sub) then
- return
- end
- copy_to_clipboard(sub)
+local function copy_sub_to_clipboard()
+ copy_to_clipboard('copy-on-demand', mp.get_property('sub-text'))
end
local function contains_non_latin_letters(str)
@@ -668,12 +669,12 @@ end
clip_autocopy = {}
clip_autocopy.enable = function()
- mp.observe_property("sub-text", "string", set_clipboard)
+ mp.observe_property("sub-text", "string", copy_to_clipboard)
mp.osd_message("Clipboard autocopy is enabled.", 1)
end
clip_autocopy.disable = function()
- mp.unobserve_property(set_clipboard)
+ mp.unobserve_property(copy_to_clipboard)
mp.osd_message("Clipboard autocopy is disabled.", 1)
end
@@ -769,6 +770,7 @@ menu.update = function()
osd:bold('Global bindings:'):newline()
osd:tab():bold('ctrl+e: '):append('Export note'):newline()
osd:tab():bold('ctrl+h: '):append('Seek to the start of the line'):newline()
+ osd:tab():bold('ctrl+c: '):append('Copy current subtitle to clipboard'):newline()
osd:draw()
end
@@ -853,6 +855,7 @@ ankiconnect.create_deck_if_doesnt_exist(config.deck_name)
mp.add_key_binding("ctrl+e", "anki-export-note", export_to_anki)
mp.add_key_binding("ctrl+h", "sub-rewind", sub_rewind)
mp.add_key_binding('a', 'mpvacious-menu-open', menu.open) -- a for advanced
+mp.add_key_binding("ctrl+c", "copy-sub-to-clipboard", copy_sub_to_clipboard)
mp.add_key_binding(null, "set-starting-line", subs.set_starting_line)
mp.add_key_binding(null, "reset-timings", subs.reset_timings)
mp.add_key_binding(null, "toggle-sub-autocopy", clip_autocopy.toggle)