local util = require('extregs.util') local storage = require('extregs.storage') local M = {} function M.get_provider(cfg) local function run(cmd, input) local argv = { 'tmux', cmd } if cfg.buffer ~= nil then assert(type(cfg.buffer) == 'string' and cfg.buffer ~= '', 'tmux.buffer must be a nonempty string') vim.list_extend(argv, { '-b', cfg.buffer }) end if cmd == 'load-buffer' then argv[#argv + 1] = '-' end return util.system(argv, input, 'tmux') end return { read = function() return storage.decode(run('show-buffer')) end, write = function(_, reg) local data = table.concat(reg.lines, '\n') if reg.type == 'V' then data = data .. '\n' end run('load-buffer', data) return true end, } end return M