diff --git a/README.md b/README.md index fb2552c5..44b7bfc2 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,7 @@ Please read the associated comments before changing the value. ssh_binary = "ssh", -- Binary to use for running SSH command scp_binary = "scp", -- Binary to use for running SSH copy commands ssh_config_file_paths = { "$HOME/.ssh/config" }, -- Which files should be considered to contain the ssh host configurations. NOTE: `Include` is respected in the provided files. + parse_osc52 = true, -- Workaround for nvim copy on remote problem (https://github.com/neovim/neovim/issues/28792) -- These are useful for password-based SSH authentication. -- It provides parsing pattern for the plugin to detect that an input is requested. diff --git a/doc/remote-nvim.txt b/doc/remote-nvim.txt index 830a5ee2..2a85b29d 100644 --- a/doc/remote-nvim.txt +++ b/doc/remote-nvim.txt @@ -174,7 +174,8 @@ value. ssh_binary = "ssh", -- Binary to use for running SSH command scp_binary = "scp", -- Binary to use for running SSH copy commands ssh_config_file_paths = { "$HOME/.ssh/config" }, -- Which files should be considered to contain the ssh host configurations. NOTE: `Include` is respected in the provided files. - + parse_osc52 = true, -- Workaround for nvim copy on remote problem (https://github.com/neovim/neovim/issues/28792) + -- These are useful for password-based SSH authentication. -- It provides parsing pattern for the plugin to detect that an input is requested. -- Each element contains the following attributes: diff --git a/lua/remote-nvim/init.lua b/lua/remote-nvim/init.lua index 2b605e4a..f9f8cfba 100644 --- a/lua/remote-nvim/init.lua +++ b/lua/remote-nvim/init.lua @@ -38,6 +38,7 @@ local utils = require("remote-nvim.utils") ---@field scp_binary string Name of binary on runtime path for scp ---@field ssh_config_file_paths string[] Location of SSH configuration files that you want the plugin to consider ---@field ssh_prompts remote-nvim.config.PluginConfig.SSHConfig.SSHPrompt[] List of SSH prompts that should be considered for input +---@field parse_osc52 boolean Should the plugin parse for OSC52 sequences and copy them to the local clipboard ---@class remote-nvim.config.RemoteConfig.LocalClientConfig ---@field callback function Function that would be called upon to start a Neovim client @@ -107,6 +108,7 @@ M.default_opts = { ssh_binary = "ssh", scp_binary = "scp", ssh_config_file_paths = { "$HOME/.ssh/config" }, + parse_osc52 = true, ssh_prompts = { { -- Handle default password style on Linux/macOS match = "password:", diff --git a/lua/remote-nvim/providers/provider.lua b/lua/remote-nvim/providers/provider.lua index d55dc026..375fa118 100644 --- a/lua/remote-nvim/providers/provider.lua +++ b/lua/remote-nvim/providers/provider.lua @@ -1032,10 +1032,26 @@ function Provider:run_command(command, desc, extra_opts, exit_cb, on_local_execu if exit_cb ~= nil then exit_cb = exit_cb(section_node) end + + local node_stdout_cb = self:_get_stdout_fn_for_node(section_node) + local stdout_cb = function(stdout_chunk) + node_stdout_cb(stdout_chunk) + + if remote_nvim.config.ssh_config.parse_osc52 then + local data = stdout_chunk:match("^%c%]%d*;c;([^\a]*)%c\\") + if data then + stdout_chunk = stdout_chunk:gsub("^%c%]%d*;c;([^\a]*)%c\\", "") + local text = vim.fn.systemlist("base64 --decode", data) + vim.fn.setreg("+", text) + vim.notify("Copied to clipboard via OSC52") + end + end + end + executor:run_command(command, { additional_conn_opts = extra_opts, exit_cb = exit_cb, - stdout_cb = self:_get_stdout_fn_for_node(section_node), + stdout_cb = stdout_cb, }) self.logger.fmt_debug("[%s][%s] Running %s completed", self.provider_type, self.unique_host_id, command) if exit_cb == nil then