Skip to content

Commit 3abb607

Browse files
ericguineric-guinnstevearc
authored
fix(ssh): config option to pass extra args to SCP (#340)
* Adding in SCP options configuration This changeset adds in additional SCP options to the config. This allows the user to specify a list of flags to send to the SCP command that will be expanded into each shell command. The primary driver for this is from newe boxes SSHing into pre 9 openSSH boxes. New openSSH uses sftp server under the hood, rather than the older SCP protocol. If you go into a system that does not have these changes, SCP fails to work. The '-O' command line flag was introduced to resolve this. Using this change, the user can now pass in `extra_scp_options = {"-O"}` to resolve the issue. * Replacing table.unpack with global unpack * lint: apply stylua * refactor: change option name and shuffle config around --------- Co-authored-by: Eric Guinn <[email protected]> Co-authored-by: Steven Arcangeli <[email protected]>
1 parent bcfc0a2 commit 3abb607

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,6 @@ require("oil").setup({
199199
["g."] = "actions.toggle_hidden",
200200
["g\\"] = "actions.toggle_trash",
201201
},
202-
-- Configuration for the floating keymaps help window
203-
keymaps_help = {
204-
border = "rounded",
205-
},
206202
-- Set to false to disable all of the above keymaps
207203
use_default_keymaps = true,
208204
view_options = {
@@ -226,6 +222,8 @@ require("oil").setup({
226222
{ "name", "asc" },
227223
},
228224
},
225+
-- Extra arguments to pass to SCP when moving/copying files over SSH
226+
extra_scp_args = {},
229227
-- EXPERIMENTAL support for performing file operations with git
230228
git = {
231229
-- Return true to automatically git add/mv/rm files
@@ -298,6 +296,10 @@ require("oil").setup({
298296
ssh = {
299297
border = "rounded",
300298
},
299+
-- Configuration for the floating keymaps help window
300+
keymaps_help = {
301+
border = "rounded",
302+
},
301303
})
302304
```
303305

doc/oil.txt

+6-4
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ CONFIG *oil-confi
9090
["g."] = "actions.toggle_hidden",
9191
["g\\"] = "actions.toggle_trash",
9292
},
93-
-- Configuration for the floating keymaps help window
94-
keymaps_help = {
95-
border = "rounded",
96-
},
9793
-- Set to false to disable all of the above keymaps
9894
use_default_keymaps = true,
9995
view_options = {
@@ -117,6 +113,8 @@ CONFIG *oil-confi
117113
{ "name", "asc" },
118114
},
119115
},
116+
-- Extra arguments to pass to SCP when moving/copying files over SSH
117+
extra_scp_args = {},
120118
-- EXPERIMENTAL support for performing file operations with git
121119
git = {
122120
-- Return true to automatically git add/mv/rm files
@@ -189,6 +187,10 @@ CONFIG *oil-confi
189187
ssh = {
190188
border = "rounded",
191189
},
190+
-- Configuration for the floating keymaps help window
191+
keymaps_help = {
192+
border = "rounded",
193+
},
192194
})
193195
<
194196

lua/oil/adapters/ssh.lua

+19-5
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,14 @@ M.perform_action = function(action, cb)
303303
local src_conn = get_connection(action.src_url)
304304
local dest_conn = get_connection(action.dest_url)
305305
if src_conn ~= dest_conn then
306-
shell.run({ "scp", "-C", "-r", url_to_scp(src_res), url_to_scp(dest_res) }, function(err)
306+
shell.run({
307+
"scp",
308+
unpack(config.extra_scp_args),
309+
"-C",
310+
"-r",
311+
url_to_scp(src_res),
312+
url_to_scp(dest_res),
313+
}, function(err)
307314
if err then
308315
return cb(err)
309316
end
@@ -322,7 +329,14 @@ M.perform_action = function(action, cb)
322329
local src_res = M.parse_url(action.src_url)
323330
local dest_res = M.parse_url(action.dest_url)
324331
if not url_hosts_equal(src_res, dest_res) then
325-
shell.run({ "scp", "-C", "-r", url_to_scp(src_res), url_to_scp(dest_res) }, cb)
332+
shell.run({
333+
"scp",
334+
unpack(config.extra_scp_args),
335+
"-C",
336+
"-r",
337+
url_to_scp(src_res),
338+
url_to_scp(dest_res),
339+
}, cb)
326340
else
327341
local src_conn = get_connection(action.src_url)
328342
src_conn:cp(src_res.path, dest_res.path, cb)
@@ -341,7 +355,7 @@ M.perform_action = function(action, cb)
341355
src_arg = fs.posix_to_os_path(path)
342356
dest_arg = url_to_scp(M.parse_url(action.dest_url))
343357
end
344-
shell.run({ "scp", "-C", "-r", src_arg, dest_arg }, cb)
358+
shell.run({ "scp", unpack(config.extra_scp_args), "-C", "-r", src_arg, dest_arg }, cb)
345359
end
346360
else
347361
cb(string.format("Bad action type: %s", action.type))
@@ -365,7 +379,7 @@ M.read_file = function(bufnr)
365379
end
366380
local tmp_bufnr = vim.fn.bufadd(tmpfile)
367381

368-
shell.run({ "scp", "-C", scp_url, tmpfile }, function(err)
382+
shell.run({ "scp", unpack(config.extra_scp_args), "-C", scp_url, tmpfile }, function(err)
369383
loading.set_loading(bufnr, false)
370384
vim.bo[bufnr].modifiable = true
371385
vim.cmd.doautocmd({ args = { "BufReadPre", bufname }, mods = { silent = true } })
@@ -405,7 +419,7 @@ M.write_file = function(bufnr)
405419
vim.cmd.write({ args = { tmpfile }, bang = true, mods = { silent = true, noautocmd = true } })
406420
local tmp_bufnr = vim.fn.bufadd(tmpfile)
407421

408-
shell.run({ "scp", "-C", tmpfile, scp_url }, function(err)
422+
shell.run({ "scp", unpack(config.extra_scp_args), "-C", tmpfile, scp_url }, function(err)
409423
vim.bo[bufnr].modifiable = true
410424
if err then
411425
vim.notify(string.format("Error writing file: %s", err), vim.log.levels.ERROR)

lua/oil/config.lua

+6-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@ local default_config = {
7373
["g."] = "actions.toggle_hidden",
7474
["g\\"] = "actions.toggle_trash",
7575
},
76-
-- Configuration for the floating keymaps help window
77-
keymaps_help = {
78-
border = "rounded",
79-
},
8076
-- Set to false to disable all of the above keymaps
8177
use_default_keymaps = true,
8278
view_options = {
@@ -100,6 +96,8 @@ local default_config = {
10096
{ "name", "asc" },
10197
},
10298
},
99+
-- Extra arguments to pass to SCP when moving/copying files over SSH
100+
extra_scp_args = {},
103101
-- EXPERIMENTAL support for performing file operations with git
104102
git = {
105103
-- Return true to automatically git add/mv/rm files
@@ -172,6 +170,10 @@ local default_config = {
172170
ssh = {
173171
border = "rounded",
174172
},
173+
-- Configuration for the floating keymaps help window
174+
keymaps_help = {
175+
border = "rounded",
176+
},
175177
}
176178

177179
-- The adapter API hasn't really stabilized yet. We're not ready to advertise or encourage people to

0 commit comments

Comments
 (0)