feat(config): add per-host/bucket extra args for SSH, S3, and FTP

Problem: `extra_scp_args`, `extra_s3_args`, and `extra_curl_args` are
global — there's no way to pass adapter-specific args only to a single
host or bucket (e.g. `-O` for a Synology NAS that requires legacy SCP
protocol, or `--endpoint-url` for an R2 bucket).

Solution: add `ssh_hosts`, `s3_buckets`, and `ftp_hosts` config tables
that map exact hostnames/bucket names to per-target arg lists. Per-target
args are appended after the global args at call time. The `scp()` helper
in `ssh.lua` accepts a `hosts` list so cross-host copies deduplicate
host lookups. `create_s3_command` in `s3fs.lua` extracts the bucket from
the command args with no call-site changes needed. `resolved_curl_args`
in `ftp.lua` is called by both `curl()` and `ftpcmd()`.

Based on: stevearc/oil.nvim#607
This commit is contained in:
Barrett Ruth 2026-03-18 12:37:14 -04:00
parent 6845cfe64a
commit 1e5c96ca2c
Signed by: barrett
GPG key ID: A6C96C9349D2FC81
7 changed files with 227 additions and 22 deletions

View file

@ -106,6 +106,17 @@ local function curl_ftp_url(url)
return table.concat(pieces, '')
end
---@param host string
---@return string[]
local function resolved_curl_args(host)
local extra = vim.deepcopy(config.extra_curl_args)
local host_cfg = config.ftp_hosts[host]
if host_cfg and host_cfg.extra_curl_args then
vim.list_extend(extra, host_cfg.extra_curl_args)
end
return extra
end
---@param url oil.ftpUrl
---@param py_lines string[]
---@param cb fun(err: nil|string)
@ -113,8 +124,8 @@ local function ftpcmd(url, py_lines, cb)
local lines = {}
local use_tls = url.scheme == 'oil-ftps://'
if use_tls then
local insecure = vim.tbl_contains(config.extra_curl_args, '--insecure')
or vim.tbl_contains(config.extra_curl_args, '-k')
local curl_args = resolved_curl_args(url.host)
local insecure = vim.tbl_contains(curl_args, '--insecure') or vim.tbl_contains(curl_args, '-k')
table.insert(lines, 'import ftplib, ssl')
table.insert(lines, 'ctx = ssl.create_default_context()')
if insecure then
@ -170,7 +181,7 @@ local function curl(url, extra_args, opts, cb)
end
local cmd = { 'curl', '-sS', '--netrc-optional' }
vim.list_extend(cmd, ssl_args(url))
vim.list_extend(cmd, config.extra_curl_args)
vim.list_extend(cmd, resolved_curl_args(url.host))
vim.list_extend(cmd, extra_args)
shell.run(cmd, opts, cb)
end

View file

@ -46,8 +46,22 @@ end
---@param cmd string[] cmd and flags
---@return string[] Shell command to run
local function create_s3_command(cmd)
local bucket
for _, arg in ipairs(cmd) do
bucket = arg:match('^s3://([^/]+)')
if bucket then
break
end
end
local extra = vim.deepcopy(config.extra_s3_args)
if bucket then
local bucket_cfg = config.s3_buckets[bucket]
if bucket_cfg and bucket_cfg.extra_s3_args then
vim.list_extend(extra, bucket_cfg.extra_s3_args)
end
end
local full_cmd = vim.list_extend({ 'aws', 's3' }, cmd)
return vim.list_extend(full_cmd, config.extra_s3_args)
return vim.list_extend(full_cmd, extra)
end
---@param url string

View file

@ -21,9 +21,21 @@ local FIELD_META = constants.FIELD_META
---@field port nil|integer
---@field path string
---@param hosts string[]
---@param args string[]
local function scp(args, ...)
local cmd = vim.list_extend({ 'scp', '-C' }, config.extra_scp_args)
local function scp(hosts, args, ...)
local extra = vim.deepcopy(config.extra_scp_args)
local seen = {}
for _, host in ipairs(hosts) do
if not seen[host] then
seen[host] = true
local host_cfg = config.ssh_hosts[host]
if host_cfg and host_cfg.extra_scp_args then
vim.list_extend(extra, host_cfg.extra_scp_args)
end
end
end
local cmd = vim.list_extend({ 'scp', '-C' }, extra)
vim.list_extend(cmd, args)
shell.run(cmd, ...)
end
@ -320,12 +332,16 @@ M.perform_action = function(action, cb)
local src_conn = get_connection(action.src_url)
local dest_conn = get_connection(action.dest_url)
if src_conn ~= dest_conn then
scp({ '-r', url_to_scp(src_res), url_to_scp(dest_res) }, function(err)
if err then
return cb(err)
scp(
{ src_res.host, dest_res.host },
{ '-r', url_to_scp(src_res), url_to_scp(dest_res) },
function(err)
if err then
return cb(err)
end
src_conn:rm(src_res.path, cb)
end
src_conn:rm(src_res.path, cb)
end)
)
else
src_conn:mv(src_res.path, dest_res.path, cb)
end
@ -339,26 +355,31 @@ M.perform_action = function(action, cb)
local src_res = M.parse_url(action.src_url)
local dest_res = M.parse_url(action.dest_url)
if not url_hosts_equal(src_res, dest_res) then
scp({ '-r', url_to_scp(src_res), url_to_scp(dest_res) }, cb)
scp(
{ src_res.host, dest_res.host },
{ '-r', url_to_scp(src_res), url_to_scp(dest_res) },
cb
)
else
local src_conn = get_connection(action.src_url)
src_conn:cp(src_res.path, dest_res.path, cb)
end
else
local src_arg
local dest_arg
if src_adapter == M then
src_arg = url_to_scp(M.parse_url(action.src_url))
local src_res = M.parse_url(action.src_url)
local src_arg = url_to_scp(src_res)
local _, path = util.parse_url(action.dest_url)
assert(path)
dest_arg = fs.posix_to_os_path(path)
local dest_arg = fs.posix_to_os_path(path)
scp({ src_res.host }, { '-r', src_arg, dest_arg }, cb)
else
local _, path = util.parse_url(action.src_url)
assert(path)
src_arg = fs.posix_to_os_path(path)
dest_arg = url_to_scp(M.parse_url(action.dest_url))
local src_arg = fs.posix_to_os_path(path)
local dest_res = M.parse_url(action.dest_url)
local dest_arg = url_to_scp(dest_res)
scp({ dest_res.host }, { '-r', src_arg, dest_arg }, cb)
end
scp({ '-r', src_arg, dest_arg }, cb)
end
else
cb(string.format('Bad action type: %s', action.type))
@ -384,7 +405,7 @@ M.read_file = function(bufnr)
end
local tmp_bufnr = vim.fn.bufadd(tmpfile)
scp({ scp_url, tmpfile }, function(err)
scp({ url.host }, { scp_url, tmpfile }, function(err)
loading.set_loading(bufnr, false)
vim.bo[bufnr].modifiable = true
vim.cmd.doautocmd({ args = { 'BufReadPre', bufname }, mods = { silent = true } })
@ -426,7 +447,7 @@ M.write_file = function(bufnr)
vim.cmd.write({ args = { tmpfile }, bang = true, mods = { silent = true, noautocmd = true } })
local tmp_bufnr = vim.fn.bufadd(tmpfile)
scp({ tmpfile, scp_url }, function(err)
scp({ url.host }, { tmpfile, scp_url }, function(err)
vim.bo[bufnr].modifiable = true
if err then
vim.notify(string.format('Error writing file: %s', err), vim.log.levels.ERROR)