1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 00:40:05 +08:00

feat(clipboard): support other clipboard command

This commit is contained in:
wsdjeg 2022-06-11 01:16:36 +08:00
parent 6285536bce
commit ee3ce867f4

View File

@ -7,16 +7,57 @@
"============================================================================= "=============================================================================
" This script is based on kamilkrz (Kamil Krześ)'s idea about using clipboard. " This script is based on kamilkrz (Kamil Krześ)'s idea about using clipboard.
function! s:set_command() abort
let yank = ''
let paste = ''
" the logic is based on nvim's clipboard provider
if has('mac')
let yank = ['pbcopy']
let paste = ['pbpaste']
elseif !empty($WAYLAND_DISPLAY) && executable('wl-copy') && executable('wl-paste')
let yank = ['wl-copy', '--foreground', '--type', 'text/plain']
let paste = ['wl-paste', '--no-newline']
elseif !empty($DISPLAY) && executable('xclip')
let yank = ['xclip', '-quiet', '-i', '-selection', 'clipboard']
let paste = ['xclip', '-o', '-selection', 'clipboard']
elseif !empty($DISPLAY) && executable('xsel')
let yank = ['xsel', '--nodetach', '-i', '-b']
let paste = ['xsel', '-o', '-b']
elseif executable('lemonade')
let yank = ['lemonade', 'copy']
let paste = ['lemonade', 'paste']
elseif executable('doitclient')
let yank = ['doitclient', 'wclip']
let paste = ['doitclient', 'wclip', '-r']
elseif executable('win32yank.exe')
if has('wsl') && getftype(exepath('win32yank.exe')) == 'link'
let win32yank = resolve(exepath('win32yank.exe'))
else
let win32yank = 'win32yank.exe'
endif
let yank = [win32yank, '-i', '--crlf']
let paste = [win32yank, '-o', '--lf']
elseif executable('termux-clipboard-set')
let yank = ['termux-clipboard-set']
let paste = ['termux-clipboard-get']
elseif !empty($TMUX) && executable('tmux')
let yank = ['tmux', 'load-buffer', '-']
let paste = ['tmux', 'save-buffer', '-']
endif
return [yank, paste]
endfunction
function! clipboard#yank() abort function! clipboard#yank() abort
call system('win32yank.exe -i --crlf', GetSelectedText()) call system(s:yank_cmd, GetSelectedText())
endfunction endfunction
" The mode can be `p` or `P` " The mode can be `p` or `P`
function! clipboard#paste(mode) abort function! clipboard#paste(mode) abort
let @" = system('win32yank.exe -o --lf') let @" = system(s:paste_cmd)
return a:mode return a:mode
endfunction endfunction
@ -26,3 +67,5 @@ function! GetSelectedText()
let result = getreg("x") let result = getreg("x")
return result return result
endfunction endfunction
let [s:yank_cmd, s:paste_cmd] = s:set_command()