2014-11-17 06:48:39 -07:00
|
|
|
" The clipboard provider uses shell commands to communicate with the clipboard.
|
|
|
|
" The provider function will only be registered if one of the supported
|
|
|
|
" commands are available.
|
2014-11-22 08:01:14 -07:00
|
|
|
let s:copy = {}
|
|
|
|
let s:paste = {}
|
2014-11-17 06:48:39 -07:00
|
|
|
|
2014-11-22 13:01:28 -07:00
|
|
|
function! s:try_cmd(cmd, ...)
|
2014-11-22 11:16:04 -07:00
|
|
|
let out = a:0 ? systemlist(a:cmd, a:1, 1) : systemlist(a:cmd, [''], 1)
|
2014-11-22 13:01:28 -07:00
|
|
|
if v:shell_error
|
|
|
|
echo "clipboard: error: ".(len(out) ? out[0] : '')
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
return out
|
|
|
|
endfunction
|
|
|
|
|
2014-11-17 06:48:39 -07:00
|
|
|
if executable('pbcopy')
|
2014-11-22 08:01:14 -07:00
|
|
|
let s:copy['+'] = 'pbcopy'
|
|
|
|
let s:paste['+'] = 'pbpaste'
|
|
|
|
let s:copy['*'] = s:copy['+']
|
|
|
|
let s:paste['*'] = s:paste['+']
|
2014-11-17 06:48:39 -07:00
|
|
|
elseif executable('xclip')
|
2014-11-22 08:01:14 -07:00
|
|
|
let s:copy['+'] = 'xclip -i -selection clipboard'
|
|
|
|
let s:paste['+'] = 'xclip -o -selection clipboard'
|
|
|
|
let s:copy['*'] = 'xclip -i -selection primary'
|
|
|
|
let s:paste['*'] = 'xclip -o -selection primary'
|
|
|
|
elseif executable('xsel')
|
|
|
|
let s:copy['+'] = 'xsel -i -b'
|
|
|
|
let s:paste['+'] = 'xsel -o -b'
|
|
|
|
let s:copy['*'] = 'xsel -i -p'
|
|
|
|
let s:paste['*'] = 'xsel -o -p'
|
2014-11-22 13:01:28 -07:00
|
|
|
else
|
|
|
|
echom 'clipboard: No shell command for communicating with the clipboard found.'
|
2014-11-17 06:48:39 -07:00
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
2014-11-22 13:01:28 -07:00
|
|
|
let s:clipboard = {}
|
2014-11-17 06:48:39 -07:00
|
|
|
|
2014-11-22 08:01:14 -07:00
|
|
|
function! s:clipboard.get(reg)
|
|
|
|
return s:try_cmd(s:paste[a:reg])
|
2014-11-17 06:48:39 -07:00
|
|
|
endfunction
|
|
|
|
|
2014-11-22 11:16:04 -07:00
|
|
|
function! s:clipboard.set(lines, regtype, reg)
|
2014-11-22 08:01:14 -07:00
|
|
|
call s:try_cmd(s:copy[a:reg], a:lines)
|
2014-11-17 06:48:39 -07:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! provider#clipboard#Call(method, args)
|
2014-11-22 08:01:14 -07:00
|
|
|
return call(s:clipboard[a:method],a:args,s:clipboard)
|
2014-11-17 06:48:39 -07:00
|
|
|
endfunction
|