diff options
| author | Josh Rahm <rahm@josher.dev> | 2026-10-18 15:49:48 -0600 |
|---|---|---|
| committer | Josh Rahm <rahm@josher.dev> | 2026-10-18 15:49:48 -0600 |
| commit | 7b15a3a4b4fb4dc6be5d53a22c20d68f8181d68b (patch) | |
| tree | d3e08937bc78441a2f3d64ad6935337cf6d9b0be /lua/extregs/ssh.lua | |
| download | extregs.nvim-main.tar.gz extregs.nvim-main.tar.bz2 extregs.nvim-main.zip | |
added a bunch of useful extregs
Diffstat (limited to 'lua/extregs/ssh.lua')
| -rw-r--r-- | lua/extregs/ssh.lua | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lua/extregs/ssh.lua b/lua/extregs/ssh.lua new file mode 100644 index 0000000..8102434 --- /dev/null +++ b/lua/extregs/ssh.lua @@ -0,0 +1,31 @@ +local util = require('extregs.util') +local storage = require('extregs.storage') +local M = {} + +local function remote_path(path) + -- Expand ~/ on the remote system; quote everything else. + if path:sub(1, 2) == '~/' then + return '"$HOME"/' .. util.shell_quote(path:sub(3)) + end + return util.shell_quote(path) +end + +function M.get_provider(cfg) + assert(type(cfg.path) == 'string' and cfg.path ~= '', 'ssh.path required') + local path = remote_path(cfg.path) + local function exec(script, input) + assert(type(cfg.host) == 'string' and cfg.host:match('^[%w_.%-]+@[%w_.%-]+$'), + 'ssh.host must be user@host') + -- SSH joins remote argv with spaces: quote the *whole* sh -c argument. + return util.system({ 'ssh', '-o', 'BatchMode=yes', cfg.host, + 'sh -c ' .. util.shell_quote(script) }, input, 'ssh') + end + return { + read = function() return storage.decode(exec('cat ' .. path)) end, + write = function(_, reg) + exec('mkdir -p "$(dirname ' .. path .. ')" && cat > ' .. path, storage.encode(reg)) + return true + end, + } +end +return M |