aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDDoSolitary <DDoSolitary@gmail.com>2020-09-01 15:27:38 +0800
committerGitHub <noreply@github.com>2020-09-01 00:27:38 -0700
commitc14a9f6fcc0e74294e98913699c8a4a79f1f7321 (patch)
treeedb77c13b2ae39935efb63d3fad7bcd953f6eb8f
parenta50cf35bdac7fe8bccd8ade3ce358daa8e00fc98 (diff)
downloadrneovim-c14a9f6fcc0e74294e98913699c8a4a79f1f7321.tar.gz
rneovim-c14a9f6fcc0e74294e98913699c8a4a79f1f7321.tar.bz2
rneovim-c14a9f6fcc0e74294e98913699c8a4a79f1f7321.zip
g:clipboard: allow command given as a list #12775
fixes #12768
-rw-r--r--runtime/autoload/provider/clipboard.vim72
-rw-r--r--runtime/doc/provider.txt8
-rw-r--r--test/functional/provider/clipboard_spec.lua10
3 files changed, 54 insertions, 36 deletions
diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim
index a96a0a61b7..275d18a5a9 100644
--- a/runtime/autoload/provider/clipboard.vim
+++ b/runtime/autoload/provider/clipboard.vim
@@ -35,8 +35,7 @@ endfunction
let s:selections = { '*': s:selection, '+': copy(s:selection) }
function! s:try_cmd(cmd, ...) abort
- let argv = split(a:cmd, " ")
- let out = systemlist(argv, (a:0 ? a:1 : ['']), 1)
+ let out = systemlist(a:cmd, (a:0 ? a:1 : ['']), 1)
if v:shell_error
if !exists('s:did_error_try_cmd')
echohl WarningMsg
@@ -55,6 +54,10 @@ function! s:cmd_ok(cmd) abort
return v:shell_error == 0
endfunction
+function! s:split_cmd(cmd) abort
+ return (type(a:cmd) == v:t_string) ? split(a:cmd, " ") : a:cmd
+endfunction
+
let s:cache_enabled = 1
let s:err = ''
@@ -71,44 +74,50 @@ function! provider#clipboard#Executable() abort
return ''
endif
- let s:copy = get(g:clipboard, 'copy', { '+': v:null, '*': v:null })
- let s:paste = get(g:clipboard, 'paste', { '+': v:null, '*': v:null })
+ let s:copy = {}
+ let s:copy['+'] = s:split_cmd(get(g:clipboard.copy, '+', v:null))
+ let s:copy['*'] = s:split_cmd(get(g:clipboard.copy, '*', v:null))
+
+ let s:paste = {}
+ let s:paste['+'] = s:split_cmd(get(g:clipboard.paste, '+', v:null))
+ let s:paste['*'] = s:split_cmd(get(g:clipboard.paste, '*', v:null))
+
let s:cache_enabled = get(g:clipboard, 'cache_enabled', 0)
return get(g:clipboard, 'name', 'g:clipboard')
elseif has('mac')
- let s:copy['+'] = 'pbcopy'
- let s:paste['+'] = 'pbpaste'
+ let s:copy['+'] = ['pbcopy']
+ let s:paste['+'] = ['pbpaste']
let s:copy['*'] = s:copy['+']
let s:paste['*'] = s:paste['+']
let s:cache_enabled = 0
return 'pbcopy'
elseif exists('$WAYLAND_DISPLAY') && executable('wl-copy') && executable('wl-paste')
- let s:copy['+'] = 'wl-copy --foreground --type text/plain'
- let s:paste['+'] = 'wl-paste --no-newline'
- let s:copy['*'] = 'wl-copy --foreground --primary --type text/plain'
- let s:paste['*'] = 'wl-paste --no-newline --primary'
+ let s:copy['+'] = ['wl-copy', '--foreground', '--type', 'text/plain']
+ let s:paste['+'] = ['wl-paste', '--no-newline']
+ let s:copy['*'] = ['wl-copy', '--foreground', '--primary', '--type', 'text/plain']
+ let s:paste['*'] = ['wl-paste', '--no-newline', '--primary']
return 'wl-copy'
elseif exists('$DISPLAY') && executable('xclip')
- let s:copy['+'] = 'xclip -quiet -i -selection clipboard'
- let s:paste['+'] = 'xclip -o -selection clipboard'
- let s:copy['*'] = 'xclip -quiet -i -selection primary'
- let s:paste['*'] = 'xclip -o -selection primary'
+ let s:copy['+'] = ['xclip', '-quiet', '-i', '-selection', 'clipboard']
+ let s:paste['+'] = ['xclip', '-o', '-selection', 'clipboard']
+ let s:copy['*'] = ['xclip', '-quiet', '-i', '-selection', 'primary']
+ let s:paste['*'] = ['xclip', '-o', '-selection', 'primary']
return 'xclip'
elseif exists('$DISPLAY') && executable('xsel') && s:cmd_ok('xsel -o -b')
- let s:copy['+'] = 'xsel --nodetach -i -b'
- let s:paste['+'] = 'xsel -o -b'
- let s:copy['*'] = 'xsel --nodetach -i -p'
- let s:paste['*'] = 'xsel -o -p'
+ let s:copy['+'] = ['xsel', '--nodetach', '-i', '-b']
+ let s:paste['+'] = ['xsel', '-o', '-b']
+ let s:copy['*'] = ['xsel', '--nodetach', '-i', '-p']
+ let s:paste['*'] = ['xsel', '-o', '-p']
return 'xsel'
elseif executable('lemonade')
- let s:copy['+'] = 'lemonade copy'
- let s:paste['+'] = 'lemonade paste'
- let s:copy['*'] = 'lemonade copy'
- let s:paste['*'] = 'lemonade paste'
+ let s:copy['+'] = ['lemonade', 'copy']
+ let s:paste['+'] = ['lemonade', 'paste']
+ let s:copy['*'] = ['lemonade', 'copy']
+ let s:paste['*'] = ['lemonade', 'paste']
return 'lemonade'
elseif executable('doitclient')
- let s:copy['+'] = 'doitclient wclip'
- let s:paste['+'] = 'doitclient wclip -r'
+ let s:copy['+'] = ['doitclient', 'wclip']
+ let s:paste['+'] = ['doitclient', 'wclip', '-r']
let s:copy['*'] = s:copy['+']
let s:paste['*'] = s:paste['+']
return 'doitclient'
@@ -118,14 +127,14 @@ function! provider#clipboard#Executable() abort
else
let win32yank = 'win32yank.exe'
endif
- let s:copy['+'] = win32yank.' -i --crlf'
- let s:paste['+'] = win32yank.' -o --lf'
+ let s:copy['+'] = [win32yank, '-i', '--crlf']
+ let s:paste['+'] = [win32yank, '-o', '--lf']
let s:copy['*'] = s:copy['+']
let s:paste['*'] = s:paste['+']
return 'win32yank'
elseif exists('$TMUX') && executable('tmux')
- let s:copy['+'] = 'tmux load-buffer -'
- let s:paste['+'] = 'tmux save-buffer -'
+ let s:copy['+'] = ['tmux', 'load-buffer', '-']
+ let s:paste['+'] = ['tmux', 'save-buffer', '-']
let s:copy['*'] = s:copy['+']
let s:paste['*'] = s:paste['+']
return 'tmux'
@@ -169,16 +178,15 @@ function! s:clipboard.set(lines, regtype, reg) abort
let s:selections[a:reg] = copy(s:selection)
let selection = s:selections[a:reg]
let selection.data = [a:lines, a:regtype]
- let argv = split(s:copy[a:reg], " ")
- let selection.argv = argv
+ let selection.argv = s:copy[a:reg]
let selection.detach = s:cache_enabled
let selection.cwd = "/"
- let jobid = jobstart(argv, selection)
+ let jobid = jobstart(selection.argv, selection)
if jobid > 0
call jobsend(jobid, a:lines)
call jobclose(jobid, 'stdin')
" xclip does not close stdout when receiving input via stdin
- if argv[0] ==# 'xclip'
+ if selection.argv[0] ==# 'xclip'
call jobclose(jobid, 'stdout')
endif
let selection.owner = jobid
diff --git a/runtime/doc/provider.txt b/runtime/doc/provider.txt
index 0a6cdc60e8..a92f3ed712 100644
--- a/runtime/doc/provider.txt
+++ b/runtime/doc/provider.txt
@@ -212,12 +212,12 @@ For example this configuration integrates the tmux clipboard: >
let g:clipboard = {
\ 'name': 'myClipboard',
\ 'copy': {
- \ '+': 'tmux load-buffer -',
- \ '*': 'tmux load-buffer -',
+ \ '+': ['tmux', 'load-buffer', '-'],
+ \ '*': ['tmux', 'load-buffer', '-'],
\ },
\ 'paste': {
- \ '+': 'tmux save-buffer -',
- \ '*': 'tmux save-buffer -',
+ \ '+': ['tmux', 'save-buffer', '-'],
+ \ '*': ['tmux', 'save-buffer', '-'],
\ },
\ 'cache_enabled': 1,
\ }
diff --git a/test/functional/provider/clipboard_spec.lua b/test/functional/provider/clipboard_spec.lua
index da9dd09129..1431054494 100644
--- a/test/functional/provider/clipboard_spec.lua
+++ b/test/functional/provider/clipboard_spec.lua
@@ -153,6 +153,16 @@ describe('clipboard', function()
eq('', eval('provider#clipboard#Error()'))
end)
+ it('g:clipboard using lists', function()
+ source([[let g:clipboard = {
+ \ 'name': 'custom',
+ \ 'copy': { '+': ['any', 'command'], '*': ['some', 'other'] },
+ \ 'paste': { '+': ['any', 'command'], '*': ['some', 'other'] },
+ \}]])
+ eq('custom', eval('provider#clipboard#Executable()'))
+ eq('', eval('provider#clipboard#Error()'))
+ end)
+
it('g:clipboard using VimL functions', function()
-- Implements a fake clipboard provider. cache_enabled is meaningless here.
source([[let g:clipboard = {