fix: actions.terminal supports ssh adapter (#152)
This commit is contained in:
parent
0e5fca35cd
commit
0ccf95ae5d
4 changed files with 83 additions and 31 deletions
|
|
@ -1,5 +1,8 @@
|
|||
local layout = require("oil.layout")
|
||||
local util = require("oil.util")
|
||||
|
||||
---@class oil.sshConnection
|
||||
---@field meta {user?: string, groups?: string[]}
|
||||
local SSHConnection = {}
|
||||
|
||||
local function output_extend(agg, output)
|
||||
|
|
@ -44,7 +47,8 @@ local function get_last_lines(bufnr, num_lines)
|
|||
end
|
||||
|
||||
---@param url oil.sshUrl
|
||||
function SSHConnection.new(url)
|
||||
---@return string[]
|
||||
function SSHConnection.create_ssh_command(url)
|
||||
local host = url.host
|
||||
if url.user then
|
||||
host = url.user .. "@" .. host
|
||||
|
|
@ -52,19 +56,27 @@ function SSHConnection.new(url)
|
|||
local command = {
|
||||
"ssh",
|
||||
host,
|
||||
}
|
||||
if url.port then
|
||||
table.insert(command, "-p")
|
||||
table.insert(command, url.port)
|
||||
end
|
||||
return command
|
||||
end
|
||||
|
||||
---@param url oil.sshUrl
|
||||
---@return oil.sshConnection
|
||||
function SSHConnection.new(url)
|
||||
local command = SSHConnection.create_ssh_command(url)
|
||||
vim.list_extend(command, {
|
||||
"/bin/bash",
|
||||
"--norc",
|
||||
"-c",
|
||||
-- HACK: For some reason in my testing if I just have "echo READY" it doesn't appear, but if I echo
|
||||
-- anything prior to that, it *will* appear. The first line gets swallowed.
|
||||
"echo '_make_newline_'; echo '===READY==='; exec /bin/bash --norc",
|
||||
}
|
||||
if url.port then
|
||||
table.insert(command, 2, "-p")
|
||||
table.insert(command, 3, url.port)
|
||||
end
|
||||
})
|
||||
local self = setmetatable({
|
||||
host = host,
|
||||
meta = {},
|
||||
commands = {},
|
||||
connected = false,
|
||||
|
|
@ -84,7 +96,7 @@ function SSHConnection.new(url)
|
|||
})
|
||||
end)
|
||||
self.term_id = term_id
|
||||
vim.api.nvim_chan_send(term_id, string.format("ssh %s\r\n", host))
|
||||
vim.api.nvim_chan_send(term_id, string.format("ssh %s\r\n", url.host))
|
||||
util.hack_around_termopen_autocmd(mode)
|
||||
|
||||
-- If it takes more than 2 seconds to connect, pop open the terminal
|
||||
|
|
@ -131,6 +143,7 @@ function SSHConnection.new(url)
|
|||
if err then
|
||||
vim.notify(string.format("Error fetching ssh connection user: %s", err), vim.log.levels.WARN)
|
||||
else
|
||||
assert(lines)
|
||||
self.meta.user = vim.trim(table.concat(lines, ""))
|
||||
end
|
||||
end)
|
||||
|
|
@ -141,6 +154,7 @@ function SSHConnection.new(url)
|
|||
vim.log.levels.WARN
|
||||
)
|
||||
else
|
||||
assert(lines)
|
||||
self.meta.groups = vim.split(table.concat(lines, ""), "%s+", { trimempty = true })
|
||||
end
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ local constants = require("oil.constants")
|
|||
local permissions = require("oil.adapters.files.permissions")
|
||||
local SSHConnection = require("oil.adapters.ssh.connection")
|
||||
local util = require("oil.util")
|
||||
|
||||
---@class oil.sshFs
|
||||
---@field conn oil.sshConnection
|
||||
local SSHFS = {}
|
||||
|
||||
local FIELD_TYPE = constants.FIELD_TYPE
|
||||
|
|
@ -20,7 +23,7 @@ local typechar_map = {
|
|||
---@param line string
|
||||
---@return string Name of entry
|
||||
---@return oil.EntryType
|
||||
---@return nil|table Metadata for entry
|
||||
---@return table Metadata for entry
|
||||
local function parse_ls_line(line)
|
||||
local typechar, perms, refcount, user, group, rem =
|
||||
line:match("^(.)(%S+)%s+(%d+)%s+(%S+)%s+(%S+)%s+(.*)$")
|
||||
|
|
@ -58,6 +61,7 @@ local function parse_ls_line(line)
|
|||
end
|
||||
|
||||
---@param url oil.sshUrl
|
||||
---@return oil.sshFs
|
||||
function SSHFS.new(url)
|
||||
return setmetatable({
|
||||
conn = SSHConnection.new(url),
|
||||
|
|
@ -94,6 +98,7 @@ function SSHFS:realpath(path, callback)
|
|||
if err then
|
||||
return callback(err)
|
||||
end
|
||||
assert(lines)
|
||||
local abspath = table.concat(lines, "")
|
||||
-- If the path was "." then the abspath might be /path/to/., so we need to trim that final '.'
|
||||
if vim.endswith(abspath, ".") then
|
||||
|
|
@ -105,6 +110,7 @@ function SSHFS:realpath(path, callback)
|
|||
-- If the file doesn't exist, treat it like a not-yet-existing directory
|
||||
type = "directory"
|
||||
else
|
||||
assert(ls_lines)
|
||||
local _
|
||||
_, type = parse_ls_line(ls_lines[1])
|
||||
end
|
||||
|
|
@ -133,6 +139,7 @@ function SSHFS:list_dir(url, path, callback)
|
|||
return callback(err)
|
||||
end
|
||||
end
|
||||
assert(lines)
|
||||
local any_links = false
|
||||
local entries = {}
|
||||
for _, line in ipairs(lines) do
|
||||
|
|
@ -159,6 +166,7 @@ function SSHFS:list_dir(url, path, callback)
|
|||
if link_err and not link_err:match("^1:") then
|
||||
return callback(link_err)
|
||||
end
|
||||
assert(link_lines)
|
||||
for _, line in ipairs(link_lines) do
|
||||
if line ~= "" and not line:match("^total") then
|
||||
local ok, name, type, meta = pcall(parse_ls_line, line)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue