Skip to content

Instantly share code, notes, and snippets.

@rcombs
Created April 12, 2024 03:51
Show Gist options
  • Save rcombs/321a3c6b42501290c75cfb3aadf49f63 to your computer and use it in GitHub Desktop.
Save rcombs/321a3c6b42501290c75cfb3aadf49f63 to your computer and use it in GitHub Desktop.
-- Default options
local opts = {
-- Additional arguments to pass to loadfile when pasting, space-separated
load_mode = "replace",
load_index = "0",
load_options = "",
}
require 'mp.options'.read_options(opts)
local utils = require 'mp.utils'
mp.add_key_binding(nil, 'copy', function()
local path = mp.get_property('path')
if path == nil then
mp.osd_message('No path loaded to copy')
else
if path:find('://') then
mp.set_property('clipboard/url', path)
else
local cwd = mp.get_property('working-directory')
path = utils.join_path(cwd, path)
mp.set_property('clipboard/path', path)
end
end
end)
mp.add_key_binding(nil, 'paste', function()
local url = mp.get_property('clipboard/url')
if url == nil then
-- fallback on plaintext clipboard, with leading/trailing whitespace trimmed
url = mp.get_property('clipboard/text'):match "^%s*(.-)%s*$"
end
if url == nil then
mp.osd_message('No path or URL on clipboard')
else
mp.commandv('loadfile', url, opts.load_mode, opts.load_index, opts.load_options)
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment