mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
clipboard: check for X on every invocation
xsel and xcopy may be available even if a valid X display is not. Also, the availability of X may change at any time, so check on each invocation. Closes #1509.
This commit is contained in:
parent
412c714448
commit
c10f7e1c62
@ -4,6 +4,15 @@
|
|||||||
let s:copy = ''
|
let s:copy = ''
|
||||||
let s:paste = ''
|
let s:paste = ''
|
||||||
|
|
||||||
|
function! s:try_cmd(cmd, ...)
|
||||||
|
let out = a:0 ? systemlist(a:cmd, a:1) : systemlist(a:cmd)
|
||||||
|
if v:shell_error
|
||||||
|
echo "clipboard: error: ".(len(out) ? out[0] : '')
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
return out
|
||||||
|
endfunction
|
||||||
|
|
||||||
if executable('pbcopy')
|
if executable('pbcopy')
|
||||||
let s:copy = 'pbcopy'
|
let s:copy = 'pbcopy'
|
||||||
let s:paste = 'pbpaste'
|
let s:paste = 'pbpaste'
|
||||||
@ -13,28 +22,21 @@ elseif executable('xsel')
|
|||||||
elseif executable('xclip')
|
elseif executable('xclip')
|
||||||
let s:copy = 'xclip -i -selection clipboard'
|
let s:copy = 'xclip -i -selection clipboard'
|
||||||
let s:paste = 'xclip -o -selection clipboard'
|
let s:paste = 'xclip -o -selection clipboard'
|
||||||
endif
|
else
|
||||||
|
echom 'clipboard: No shell command for communicating with the clipboard found.'
|
||||||
if s:copy == ''
|
|
||||||
echom 'No shell command for communicating with the clipboard found.'
|
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let s:methods = {}
|
let s:clipboard = {}
|
||||||
|
|
||||||
function! s:ClipboardGet(...)
|
function! s:clipboard.get(...)
|
||||||
return systemlist(s:paste)
|
return s:try_cmd(s:paste)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:ClipboardSet(...)
|
function! s:clipboard.set(...)
|
||||||
call systemlist(s:copy, a:1)
|
call s:try_cmd(s:copy, a:1)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:methods = {
|
|
||||||
\ 'get': function('s:ClipboardGet'),
|
|
||||||
\ 'set': function('s:ClipboardSet')
|
|
||||||
\ }
|
|
||||||
|
|
||||||
function! provider#clipboard#Call(method, args)
|
function! provider#clipboard#Call(method, args)
|
||||||
return s:methods[a:method](a:args)
|
return s:clipboard[a:method](a:args)
|
||||||
endfunction
|
endfunction
|
||||||
|
Loading…
Reference in New Issue
Block a user