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:
parent
6845cfe64a
commit
1e5c96ca2c
7 changed files with 227 additions and 22 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -118,6 +118,9 @@ local default_config = {
|
|||
extra_s3_args = {},
|
||||
-- Extra arguments to pass to curl for FTP operations
|
||||
extra_curl_args = {},
|
||||
ssh_hosts = {},
|
||||
s3_buckets = {},
|
||||
ftp_hosts = {},
|
||||
-- EXPERIMENTAL support for performing file operations with git
|
||||
git = {
|
||||
-- Return true to automatically git add/mv/rm files
|
||||
|
|
@ -233,6 +236,15 @@ default_config.adapter_aliases = {}
|
|||
-- here we can get some performance wins
|
||||
default_config.view_options.highlight_filename = nil
|
||||
|
||||
---@class (exact) oil.SshHostConfig
|
||||
---@field extra_scp_args? string[]
|
||||
|
||||
---@class (exact) oil.S3BucketConfig
|
||||
---@field extra_s3_args? string[]
|
||||
|
||||
---@class (exact) oil.FtpHostConfig
|
||||
---@field extra_curl_args? string[]
|
||||
|
||||
---@class oil.Config
|
||||
---@field adapters table<string, string> Hidden from SetupOpts
|
||||
---@field adapter_aliases table<string, string> Hidden from SetupOpts
|
||||
|
|
@ -259,6 +271,9 @@ default_config.view_options.highlight_filename = nil
|
|||
---@field extra_scp_args string[]
|
||||
---@field extra_s3_args string[]
|
||||
---@field extra_curl_args string[]
|
||||
---@field ssh_hosts table<string, oil.SshHostConfig>
|
||||
---@field s3_buckets table<string, oil.S3BucketConfig>
|
||||
---@field ftp_hosts table<string, oil.FtpHostConfig>
|
||||
---@field git oil.GitOptions
|
||||
---@field float oil.FloatWindowConfig
|
||||
---@field preview_win oil.PreviewWindowConfig
|
||||
|
|
@ -294,6 +309,9 @@ local M = {}
|
|||
---@field extra_scp_args? string[] Extra arguments to pass to SCP when moving/copying files over SSH
|
||||
---@field extra_s3_args? string[] Extra arguments to pass to aws s3 when moving/copying files using aws s3
|
||||
---@field extra_curl_args? string[] Extra arguments to pass to curl for FTP operations
|
||||
---@field ssh_hosts? table<string, oil.SshHostConfig> Per-host SCP arg overrides
|
||||
---@field s3_buckets? table<string, oil.S3BucketConfig> Per-bucket S3 arg overrides
|
||||
---@field ftp_hosts? table<string, oil.FtpHostConfig> Per-host curl arg overrides
|
||||
---@field git? oil.SetupGitOptions EXPERIMENTAL support for performing file operations with git
|
||||
---@field float? oil.SetupFloatWindowConfig Configuration for the floating window in oil.open_float
|
||||
---@field preview_win? oil.SetupPreviewWindowConfig Configuration for the file preview window
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue