2024-01-26 11:06:13 -07:00
|
|
|
local tty = false
|
|
|
|
for _, ui in ipairs(vim.api.nvim_list_uis()) do
|
|
|
|
if ui.chan == 1 and ui.stdout_tty then
|
|
|
|
tty = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2023-11-16 11:21:24 -07:00
|
|
|
|
2023-11-16 12:56:05 -07:00
|
|
|
if not tty or vim.g.clipboard ~= nil or vim.o.clipboard ~= '' or not os.getenv('SSH_TTY') then
|
2023-11-16 11:21:24 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-12-05 11:01:32 -07:00
|
|
|
require('vim.termcap').query('Ms', function(cap, found, seq)
|
|
|
|
if not found then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-11-16 11:21:24 -07:00
|
|
|
assert(cap == 'Ms')
|
|
|
|
|
2023-11-16 12:56:05 -07:00
|
|
|
-- Check 'clipboard' and g:clipboard again to avoid a race condition
|
|
|
|
if vim.o.clipboard ~= '' or vim.g.clipboard ~= nil then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2023-11-16 11:21:24 -07:00
|
|
|
-- If the terminal reports a sequence other than OSC 52 for the Ms capability
|
|
|
|
-- then ignore it. We only support OSC 52 (for now)
|
2023-12-05 11:01:32 -07:00
|
|
|
if not seq or not seq:match('^\027%]52') then
|
2023-11-16 11:21:24 -07:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local osc52 = require('vim.ui.clipboard.osc52')
|
|
|
|
|
|
|
|
vim.g.clipboard = {
|
|
|
|
name = 'OSC 52',
|
|
|
|
copy = {
|
|
|
|
['+'] = osc52.copy('+'),
|
|
|
|
['*'] = osc52.copy('*'),
|
|
|
|
},
|
|
|
|
paste = {
|
|
|
|
['+'] = osc52.paste('+'),
|
|
|
|
['*'] = osc52.paste('*'),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end)
|