Add keybindings to play URLs from clipboard

This commit is contained in:
Sonny Bakker 2026-08-21 17:22:52 +02:00
parent 04be1ffea0
commit f131e6d905
2 changed files with 35 additions and 2 deletions

View file

@ -0,0 +1,28 @@
-- {{ ansible_managed }}
-- Note that the mp global is injected by mpv when the script is ran.
local utils = require 'mp.utils'
local function paste_from_clipboard(command)
local res = utils.subprocess({ args = { 'wl-paste', '--no-newline' } })
if res.status == 0 and res.stdout then
local url = res.stdout:gsub("^%s*(.-)%s*$", "%1") -- trim whitespace
if url ~= "" then
mp.commandv("loadfile", url, command)
mp.osd_message("Processed: " .. url)
end
end
end
local function append_from_clipboard()
paste_from_clipboard("append")
end
local function replace_from_clipboard()
paste_from_clipboard("replace")
end
-- TODO: add keybinding that works with idle screen
mp.add_key_binding("Shift+MBTN_RIGHT", "append_clipboard", append_from_clipboard)
mp.add_key_binding("Shift+MBTN_LEFT", "replace_clipboard", replace_from_clipboard)