mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	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.
This commit is contained in:
		| @@ -13,6 +13,12 @@ function! s:normalize_path(s) abort | |||||||
|   return substitute(substitute(a:s, '\', '/', 'g'), '/\./\|/\+', '/', 'g') |   return substitute(substitute(a:s, '\', '/', 'g'), '/\./\|/\+', '/', 'g') | ||||||
| endfunction | 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. | " Simple version comparison. | ||||||
| function! s:version_cmp(a, b) abort | function! s:version_cmp(a, b) abort | ||||||
|   let a = split(a:a, '\.', 0) |   let a = split(a:a, '\.', 0) | ||||||
| @@ -120,6 +126,13 @@ endfunction | |||||||
| function! s:check_clipboard() abort | function! s:check_clipboard() abort | ||||||
|   call health#report_start('Clipboard (optional)') |   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() |   let clipboard_tool = provider#clipboard#Executable() | ||||||
|   if exists('g:clipboard') && empty(clipboard_tool) |   if exists('g:clipboard') && empty(clipboard_tool) | ||||||
|     call health#report_error( |     call health#report_error( | ||||||
|   | |||||||
| @@ -26,7 +26,7 @@ let s:selections = { '*': s:selection, '+': copy(s:selection) } | |||||||
|  |  | ||||||
| function! s:try_cmd(cmd, ...) abort | function! s:try_cmd(cmd, ...) abort | ||||||
|   let argv = split(a:cmd, " ") |   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 v:shell_error | ||||||
|     if !exists('s:did_error_try_cmd') |     if !exists('s:did_error_try_cmd') | ||||||
|       echohl WarningMsg |       echohl WarningMsg | ||||||
| @@ -64,7 +64,7 @@ function! provider#clipboard#Executable() abort | |||||||
|     let s:paste = get(g:clipboard, 'paste', { '+': v:null, '*': v:null }) |     let s:paste = get(g:clipboard, 'paste', { '+': v:null, '*': v:null }) | ||||||
|     let s:cache_enabled = get(g:clipboard, 'cache_enabled', 0) |     let s:cache_enabled = get(g:clipboard, 'cache_enabled', 0) | ||||||
|     return get(g:clipboard, 'name', 'g:clipboard') |     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:copy['+'] = 'pbcopy' | ||||||
|     let s:paste['+'] = 'pbpaste' |     let s:paste['+'] = 'pbpaste' | ||||||
|     let s:copy['*'] = s:copy['+'] |     let s:copy['*'] = s:copy['+'] | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Justin M. Keyes
					Justin M. Keyes