-
-
Save rcombs/321a3c6b42501290c75cfb3aadf49f63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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