aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-01-30 22:35:33 +0100
committerJustin M. Keyes <justinkz@gmail.com>2018-01-31 11:37:05 +0100
commit6452831cf985bd31d16eb5a04b345038f45d203f (patch)
treefa2fd5c857891b078e2d0debc73ae9e0a56d45b6
parent649123d07c13d3314b7f97abdd3d8094b32fbefe (diff)
downloadrneovim-6452831cf985bd31d16eb5a04b345038f45d203f.tar.gz
rneovim-6452831cf985bd31d16eb5a04b345038f45d203f.tar.bz2
rneovim-6452831cf985bd31d16eb5a04b345038f45d203f.zip
clipboard: macOS: fallback to tmux if pbcopy is broken #7940
On some versions of macOS, pbcopy doesn't work in tmux <2.6 https://superuser.com/q/231130 Fallback to tmux in that case. Add a healthcheck for this scenario.
-rw-r--r--runtime/autoload/health/provider.vim13
-rw-r--r--runtime/autoload/provider/clipboard.vim4
2 files changed, 15 insertions, 2 deletions
diff --git a/runtime/autoload/health/provider.vim b/runtime/autoload/health/provider.vim
index d1239db605..ae106095f9 100644
--- a/runtime/autoload/health/provider.vim
+++ b/runtime/autoload/health/provider.vim
@@ -13,6 +13,12 @@ function! s:normalize_path(s) abort
return substitute(substitute(a:s, '\', '/', 'g'), '/\./\|/\+', '/', 'g')
endfunction
+" Returns TRUE if `cmd` exits with success, else FALSE.
+function! s:cmd_ok(cmd) abort
+ call system(a:cmd)
+ return v:shell_error == 0
+endfunction
+
" Simple version comparison.
function! s:version_cmp(a, b) abort
let a = split(a:a, '\.', 0)
@@ -120,6 +126,13 @@ endfunction
function! s:check_clipboard() abort
call health#report_start('Clipboard (optional)')
+ if !empty($TMUX) && executable('tmux') && executable('pbcopy') && !s:cmd_ok('pbcopy')
+ let tmux_version = matchstr(system('tmux -V'), '\d\+\.\d\+')
+ call health#report_error('pbcopy does not work with tmux version: '.tmux_version,
+ \ ['Install tmux 2.6+. https://superuser.com/q/231130',
+ \ 'or use tmux with reattach-to-user-namespace. https://superuser.com/a/413233'])
+ endif
+
let clipboard_tool = provider#clipboard#Executable()
if exists('g:clipboard') && empty(clipboard_tool)
call health#report_error(
diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim
index e5a6e4748a..9e2e6046f8 100644
--- a/runtime/autoload/provider/clipboard.vim
+++ b/runtime/autoload/provider/clipboard.vim
@@ -26,7 +26,7 @@ let s:selections = { '*': s:selection, '+': copy(s:selection) }
function! s:try_cmd(cmd, ...) abort
let argv = split(a:cmd, " ")
- let out = a:0 ? systemlist(argv, a:1, 1) : systemlist(argv, [''], 1)
+ let out = systemlist(argv, (a:0 ? a:1 : ['']), 1)
if v:shell_error
if !exists('s:did_error_try_cmd')
echohl WarningMsg
@@ -64,7 +64,7 @@ function! provider#clipboard#Executable() abort
let s:paste = get(g:clipboard, 'paste', { '+': v:null, '*': v:null })
let s:cache_enabled = get(g:clipboard, 'cache_enabled', 0)
return get(g:clipboard, 'name', 'g:clipboard')
- elseif has('mac') && executable('pbcopy')
+ elseif has('mac') && executable('pbcopy') && s:cmd_ok('pbcopy')
let s:copy['+'] = 'pbcopy'
let s:paste['+'] = 'pbpaste'
let s:copy['*'] = s:copy['+']