fix(osc52): enable OSC 52 by default in tmux sessions (#26072)

tmux has a set-clipboard option which, when set to 'on', allows
applications to set the system clipboard using the usual OSC 52 escape
sequence.
This commit is contained in:
Gregory Anders
2023-11-16 13:56:05 -06:00
committed by GitHub
parent 2f64546dc1
commit 5d75d9aef2
2 changed files with 6 additions and 8 deletions

View File

@@ -268,7 +268,6 @@ does as long as all of the following are true:
• |g:clipboard| is unset • |g:clipboard| is unset
• 'clipboard' is not set to "unnamed" or "unnamedplus" • 'clipboard' is not set to "unnamed" or "unnamedplus"
• $SSH_TTY is set • $SSH_TTY is set
• $TMUX is unset
If any of the above conditions are not met then the OSC 52 clipboard provider If any of the above conditions are not met then the OSC 52 clipboard provider
will not be used by default and Nvim will fall back to discovering a will not be used by default and Nvim will fall back to discovering a

View File

@@ -2,19 +2,18 @@ local tty = vim.iter(vim.api.nvim_list_uis()):any(function(ui)
return ui.chan == 1 and ui.stdout_tty return ui.chan == 1 and ui.stdout_tty
end) end)
if if not tty or vim.g.clipboard ~= nil or vim.o.clipboard ~= '' or not os.getenv('SSH_TTY') then
not tty
or vim.g.clipboard ~= nil
or vim.o.clipboard ~= ''
or not os.getenv('SSH_TTY')
or os.getenv('TMUX')
then
return return
end end
require('vim.termcap').query('Ms', function(cap, seq) require('vim.termcap').query('Ms', function(cap, seq)
assert(cap == 'Ms') assert(cap == 'Ms')
-- Check 'clipboard' and g:clipboard again to avoid a race condition
if vim.o.clipboard ~= '' or vim.g.clipboard ~= nil then
return
end
-- If the terminal reports a sequence other than OSC 52 for the Ms capability -- If the terminal reports a sequence other than OSC 52 for the Ms capability
-- then ignore it. We only support OSC 52 (for now) -- then ignore it. We only support OSC 52 (for now)
if not seq:match('^\027%]52') then if not seq:match('^\027%]52') then