Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lua/remote-sshfs/connections.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ M.mount_host = function(host, mount_dir, ask_pass)
return
end
-- Setup new connection
local remote_host = host["Name"]
-- Determine actual remote hostname (honoring HostName overrides)
local target_host = host["HostName"] or host["Name"]

-- Build SSHFS command as argument list to avoid shell quoting issues
local cmd = { "sshfs" }
Expand Down Expand Up @@ -121,7 +122,7 @@ M.mount_host = function(host, mount_dir, ask_pass)
table.insert(cmd, "password_stdin")
end
-- Build remote spec: [user@]host[:path]
local spec = remote_host
local spec = target_host
if host["User"] then
spec = host["User"] .. "@" .. spec
end
Expand All @@ -131,7 +132,7 @@ M.mount_host = function(host, mount_dir, ask_pass)
table.insert(cmd, mount_dir)

local function start_job()
vim.notify("Connecting to host (" .. remote_host .. ")...")
vim.notify("Connecting to host (" .. (host["Name"] or target_host) .. ")...")
local skip_clean = false
local spec_mount_point = mount_dir .. "/"
local spec_host = host
Expand Down
24 changes: 24 additions & 0 deletions lua/remote-sshfs/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,30 @@ M.parse_hosts_from_configs = function(ssh_configs)
end
end
end
-- Resolve configured hostnames via `ssh -G`, to honor Include/Match/HostName directives
if vim.fn.executable "ssh" == 1 then
for alias, host in pairs(hosts) do
-- Use ssh to dump effective config for this host
local lines = vim.fn.systemlist { "ssh", "-G", alias }
if vim.v.shell_error == 0 then
for _, line in ipairs(lines) do
local key, value = line:match "^%s*(%S+)%s+(.*)$"
if key and value then
local k = key:lower()
if k == "hostname" then
host["HostName"] = value
elseif k == "user" then
host["User"] = value
elseif k == "port" then
host["Port"] = value
elseif k == "identityfile" then
host["IdentityFile"] = value
end
end
end
end
end
end
return hosts
end

Expand Down