Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for pasting from primary clipboard buffer on linux #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion script-opts/SmartCopyPaste.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
device=auto

#--copy command that will be used in Linux. OR write a different command
linux_copy=xclip -silent -selection clipboard -in
linux_copy=xclip -silent -selection clipboard -i

#--paste command that will be used in Linux. OR write a different command
linux_paste=xclip -selection clipboard -o

#--paste command that will be used in Linux on middle click
linux_paste_primary=xclip -selection primary -o

#--copy command that will be used in MAC. OR write a different command
mac_copy=pbcopy

Expand Down Expand Up @@ -70,6 +73,9 @@ paste_specific_behavior=playlist
#--Keybind that will be used to paste based on the paste behavior specified
paste_specific_keybind=["ctrl+alt+v", "ctrl+alt+V", "meta+alt+v", "meta+alt+V"]

#--Keybind that will be used to paste from primary buffer on Linux
paste_primary_keybind=["MBTN_MID"]

#--add below (after a comma) any protocol you want paste to work with; e.g: ,'ftp://'. Or set it as "" by deleting all defined protocols to make paste works with any protocol.
paste_protocols=["https?://", "magnet:", "rtmp:", "file:"]

Expand Down
33 changes: 22 additions & 11 deletions scripts/SmartCopyPaste.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ local o = {

-----Script Settings----
device = 'auto', --'auto' is for automatic device detection, or manually change to: 'windows' or 'mac' or 'linux'
linux_copy = 'xclip -silent -selection clipboard -in', --copy command that will be used in Linux. OR write a different command
linux_copy = 'xclip -silent -selection clipboard -i', --copy command that will be used in Linux. OR write a different command
linux_paste = 'xclip -selection clipboard -o', --paste command that will be used in Linux. OR write a different command
linux_paste_primary = 'xclip -selection primary -o', --paste command that will be used in Linux on middle click
mac_copy = 'pbcopy', --copy command that will be used in MAC. OR write a different command
mac_paste = 'pbpaste', --paste command that will be used in MAC. OR write a different command
windows_copy = 'powershell', --'powershell' is for using windows powershell to copy. OR write the copy command, e.g: ' clip'
Expand Down Expand Up @@ -45,6 +46,9 @@ local o = {
paste_specific_keybind=[[
["ctrl+alt+v", "ctrl+alt+V", "meta+alt+v", "meta+alt+V"]
]], --Keybind that will be used to paste based on the paste behavior specified
paste_primary_keybind=[[
["MBTN_MID"]
]], --Keybind that will be used to paste from primary buffer on Linux
paste_protocols=[[
["https?://", "magnet:", "rtmp:", "file:"]
]], --add above (after a comma) any protocol you want paste to work with; e.g: ,'ftp://'. Or set it as "" by deleting all defined protocols to make paste works with any protocol.
Expand Down Expand Up @@ -79,6 +83,7 @@ o.copy_keybind = utils.parse_json(o.copy_keybind)
o.paste_keybind = utils.parse_json(o.paste_keybind)
o.copy_specific_keybind = utils.parse_json(o.copy_specific_keybind)
o.paste_specific_keybind = utils.parse_json(o.paste_specific_keybind)
o.paste_primary_keybind = utils.parse_json(o.paste_primary_keybind)
o.paste_protocols = utils.parse_json(o.paste_protocols)
o.paste_extensions = utils.parse_json(o.paste_extensions)
o.paste_subtitles = utils.parse_json(o.paste_subtitles)
Expand Down Expand Up @@ -287,11 +292,14 @@ function get_time_attribute(target_path)
end


function get_clipboard()
function get_clipboard(use_primary)
local clipboard
if o.device == 'linux' then
clipboard = os.capture(o.linux_paste)
return clipboard
if use_primary then
return os.capture(o.linux_paste_primary)
else
return os.capture(o.linux_paste)
end
elseif o.device == 'windows' then
if o.windows_paste == 'powershell' then
local args = {
Expand Down Expand Up @@ -686,13 +694,13 @@ function multipaste()
end


function paste()
function paste(use_primary)
if o.osd_messages == true then
mp.osd_message("Pasting...")
end
msg.info("Pasting...")

clip = get_clipboard(clip)
clip = get_clipboard(use_primary)
if not clip then msg.error('Error: clip is null' .. clip) return end
clip, clip_file, clip_time, clip_table = parse_clipboard(clip)

Expand Down Expand Up @@ -766,15 +774,15 @@ function paste()
end


function paste_specific(action)
function paste_specific(action, use_primary)
if not action then return end

if o.osd_messages == true then
mp.osd_message("Pasting...")
end
msg.info("Pasting...")

clip = get_clipboard(clip)
clip = get_clipboard(use_primary)
if not clip then msg.error('Error: clip is null' .. clip) return end
clip, clip_file, clip_time, clip_table = parse_clipboard(clip)

Expand Down Expand Up @@ -832,7 +840,7 @@ end
mp.register_event('file-loaded', function()
filePath, fileTitle = get_path()
if clipboard_pasted == true then
clip = get_clipboard(clip)
clip = get_clipboard()
if not clip then msg.error('Error: clip is null' .. clip) return end
clip, clip_file, clip_time, clip_table = parse_clipboard(clip)

Expand Down Expand Up @@ -870,6 +878,9 @@ mp.register_event('file-loaded', function()
end)

bind_keys(o.copy_keybind, 'copy', copy)
bind_keys(o.copy_specific_keybind, 'copy-specific', function()copy_specific(o.copy_specific_behavior)end)
bind_keys(o.copy_specific_keybind, 'copy-specific', function() copy_specific(o.copy_specific_behavior) end)
bind_keys(o.paste_keybind, 'paste', paste)
bind_keys(o.paste_specific_keybind, 'paste-specific', function()paste_specific(o.paste_specific_behavior)end)
bind_keys(o.paste_specific_keybind, 'paste-specific', function() paste_specific(o.paste_specific_behavior) end)
if o.device == 'linux' then
bind_keys(o.paste_primary_keybind, 'paste-primary', function() paste(true) end)
end